I'm struggling with a really basic collection mapping. It's a unidirectional one-to-many between an simple class and java.lang.Integer. I don't want to create a wrapper class to represent the Integer.
Context: A BIN is a unqiue identifier. A BIN Group is a named grouping of such identifiers, with no duplicates and in no particular order.
The code looks like this:
Code:
class BinGroup {
/* Insert basic getters and setters for all of the member vars. */
private Long id; // Unique identifier
private String name; // Textual name
private Set bins; // Collection of java.lang.Integers
}
Note: I don't really care what Collection type I use here (Set is propbably most appropriate though).
The database tables look like this:
Code:
bin_groups {
id : bigint(8) # Primary key / Identity
name : varchar(50) # Not-null
}
bin_group_membership {
group_id : bigint(8)
bin : int(4) # Not-null
}
I want to be able to fetch a BinGroup given an id, and have the collection of BINs populated at the same time. When I make changees to the collection of BINs, and save() the BinGroup, it should be updated. The SQL to fetch all of the BINs for a BinGroup looks like "select BIN from bin_group_membership where group_id = ?;"
Mapping would be easy if the contained class wasn't an Integer, but rather, something I've created. I don't want to create a wrapper class though because I don't want to have to add an id column to bin_group_membership (mapping to an existing db).
My mapping thus far looks like:
Code:
<class name="eg.BinGroup" table="bin_groups">
<id name="id" column="id" type="java.lang.Long">
<generator class="identity" />
</id>
<property name="name" type="java.lang.String" column="bin_group_name" />
<set name="bins" table="bin_group_membership">
<key column="group_id" />
<one-to-many class="java.util.Integer" />
</set>
</class>
This mapping throws this exception during initialization: net.sf.hibernate.MappingException: Associated class not found
This is such a basic database mapping, I clearly must be missing something... unfortunately, it's not a very easy thing to search/google. Any help or pointers would be appreciated.