I want to assign an id (using sequences) to a many-to-many relationship. So if I have two object instances with ID's A_ID and B_ID, I want the relationship table to assign that relationship with an id, R_ID (used as a foreign key in other tables.
Hibernate version: 3.2.4
Mapping documents:
classA.hbm.xml
<hibernate-mapping>
<class name="classA" table="TableA " optimistic-lock="none">
<id name="classAId" type="java.lang.Integer">
<column name="A_ID" precision="22" scale="0" />
<generator class="sequence">
<param name="sequence">MY_SEQ</param>
</generator>
</id>
... (removed properties)
<set name="bees" table="TableAB_Reltn" cascade="all">
<key column="A_ID" not-null="true"/>
<many-to-many column="B_ID" class="ClassB"/>
</set>
</class>
</hibernate-mapping>
classB.hbm.xml
<hibernate-mapping>
<class name="classB" table="TableB">
<id name="classBId" type="java.lang.Integer" unsaved-value="0">
<column name="B_ID" precision="22" scale="0" />
<generator class="sequence">
<param name="sequence">MY_SEQ</param>
</generator>
</id>
... (does not have an inverse set definition)
</hibernate-mapping>
Name and version of the database you are using:
Oracle10g
The generated SQL (show_sql=true):
Hibernate: select HIT_SEQ.nextval from dual
Hibernate: select HIT_SEQ.nextval from dual
Hibernate: select HIT_SEQ.nextval from dual
Hibernate: insert into HIT.HIT_TIER (NAME, TIER_ID) values (?, ?)
Hibernate: insert into HIT.HIT_SUBTIER (NAME, SUBTIER_ID) values (?, ?)
Hibernate: insert into HIT.HIT_SUBTIER (NAME, SUBTIER_ID) values (?, ?)
Hibernate: insert into HIT.HIT_TIER_SUBTIER_RELTN (TIER_ID, SUBTIER_ID) values (?, ?)
Hibernate: insert into HIT.HIT_TIER_SUBTIER_RELTN (TIER_ID, SUBTIER_ID) values (?, ?)
|