Hi,
I'm rather new to Hibernate so please bare with me.
I have a User class with a collection of Group objects in it. In the database I have a USER table, a GROUP table and a USER_GROUP table defining which groups are associated with which user. This all worked using OJB, however I don't understand how to configure the <list> mapping for Hibernate. I've placed below example code, db schemas and the mappings, can somebody tell me how I should write this <list> mapping please? My version below just doesn't work!
The Java
Code:
public class User
{
private Collection groups;
...
}
public class Group
{
...
}
The DB SchemaCode:
CREATE TABLE USER(
ID INT NOT NULL,
...
);
CREATE TABLE GROUP(
ID INT NOT NULL,
...
);
CREATE TABLE USER_GROUP(
USER_ID INT(11),
GROUP_ID INT(11)
);
The MappingsCode:
<class name="Group" table="GROUP">
<id name="id"
type="integer"
column="ID">
<generator class="assigned"/>
</id>
...
</class>
<class name="User" table="USER"
>
<id name="id"
type="integer"
unsaved-value="null"
column="ID">
<generator class="assigned"/>
</id>
...
<list name="groups"
table="USER_GROUP"
inverse="true"
lazy="true">
<key column="USER_ID"/>
<one-to-many
column="GROUP_ID"
class="Group"
/>
</list>
</class>