Hibernate version: 2.1.7 DB: Oracle 9i
Hi, I am experiencing problems trying to derive a composite primary key from the id's generated by two other objects. These Id's are generated using a custom generator class.
For example, if I had an object C which takes a id generated from objects A and B, how do I get Hibernate to assign both of the new id's to the object C?
I can get it to work in the case of a normal one to many relationship but I'm not sure how to do it for two objects.
Here is an example of what I have tried.
<hibernate-mapping>
<class name="com.A" table="A">
<id name="aId" column="a_id">
<generator class="com.HibernateIdGenerator"/>
</id>
<bag name="Cs" table="C" access="field">
<key>
<column name="a_id"/>
</key>
</bag>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="com.B" table="B">
<id name="bId" column="b_id">
<generator class="com.HibernateIdGenerator"/>
</id>
<bag name="Cs" table="C" access="field">
<key>
<column name="b_id"/>
</key>
</bag>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="com.C" table="C">
<composite-id>
<key-property name="aId" column="a_id" access="field"/>
<key-property name="bId" column="b_id" access="field"/>
</composite-id>
</class>
</hibernate-mapping>
Does anyone if this is possible using an id generator?
Thanks,
Ian
|