The parent table :
create table my_batch( batch_id int identity(1,1) primary key, batch_name varchar(100) NOT NULL, created_date datetime DEFAULT GETDATE(), description varchar(200), );
Needs to have the BATCH_IDs stored in the child table :
create table batch_batches( parent_batch_id int, child_batch_id int, Foreign Key(parent_batch_id) references cube_batch(batch_id), Foreign Key(child_batch_id) references cube_batch(batch_id), );
Where both the PARENT_BATCH_ID and CHILD_BATCH_ID should reference the BATCH_ID which is the PK.
My HBM has:
<class name="com.myApp.hibernate.BatchBatches" table="BATCH_BATCHES" > <composite-id name="parentBatchId" > <key-property name="parentBatchId" column="parent_batch" type="integer"/> <key-many-to-one name="parentBatchId" class="com.myApp.cube.hibernate.CubeBatch" column="batch_id" /> <key-property name="childBatchId" column="batch_id" type="integer"/> <key-many-to-one name="childBatchId" class="com.myApp.cube.hibernate.MyBatch" column="batch_id" /> </composite-id> </class>
which gives this Error:
org.hibernate.MappingException: Repeated column in mapping for entity: com.myApp.cube.hib ernate.BatchBatches column: batch_id (should be mapped with insert="false" update="false")
What could be the best way to map this kind of a double FK- single PK relation?
Please help..!
|