I have a table of Employees and a table of Groups.
An employee may belong to any number of groups so there is a many-to-many relationship in there. Also i need the date to know when the employee got into the group, so the schema is something like this:
Employee
idEmployee (PK)
salary
dob
---
Group
idGroup (PK)
name
---
GroupEmployee
idEmployee (PK, FK)
idGroup (PK, FK)
date
so, i was trying to map this ussing Hibernate (2.1) and Oracle 9i database.
this are the mappings i have
Code:
<class name="com.pba.GroupEmployee" table="GROUPEMPLOYEE">
<composite-id>
<key-property name="idEmployee" column="IDEMPLOYEE" type="integer"/>
<key-property name="idGroup" column="IDGROUP" type="integer"/>
</composite-id>
<property name="date" column="DATE" type="java.util.Date" />
</class>
<class name="com.pba.Employee" table="EMPLOYEE">
<id name="idEmployee" column="IDEMPLOYEE" type="integer" unsaved-value="null" >
<generator class="sequence">
<param name="sequence">EMP_SEQ</param>
</generator>
</id>
<property name="dob" column="DOB" type="java.util.Date"/>
<property name="salary" column="SALARY" type="float"/>
<set name="groups" table="GROUPEMPLOYEE">
<key column="IDEMPLOYEE"/>
<one-to-many class="com.pba.GROUPEMPLOYEE"/>
</set>
</class>
<class name="com.pba.Group" table="GROUP">
<id name="idGroup" column="IDGROUP" type="integer" unsaved-value="null" >
<generator class="sequence">
<param name="sequence">GRP_SEQ</param>
</generator>
</id>
<property name="name" column="NAME" type="string"/>
</class>
Then i'm trying to insert an employee with a set of 3 groups, but it never inserts anything on the GROUPEMPLOYEE table.
The generated sql goes like (in this case i insert the employee first and then i add the groups to it...)
Code:
Hibernate: update EMPLOYEE set ... {All employee data goes here}
Hibernate: update GROUPEMPLOYEE set date=? where IDEMPLOYEE=? and IDGROUP=?
Hibernate: update GROUPEMPLOYEE set IDEMPLOYEE=? where IDEMPLOYEE=? and IDGROUP=?
How can it do it then to be able to insert the data in the GROUEMPLOYEE table ??
Thanx