-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Many to Many Join table with generator ID
PostPosted: Tue Feb 24, 2009 2:10 pm 
Newbie

Joined: Mon Jan 26, 2009 12:14 pm
Posts: 8
Hello,
Lets say I have a situation with Parent, Child and ParentChild table.
Lets also say that ParentChild table has a non-intelligent sequence ID used for its primary key along with the PK of both Parent and Child tables. I want to map the relationship as many-to-many in the config and have the Parent as the driver so that if I remove a child it will delete the join table row and then the child row. I mapped this originally but was unable to get it to insert the join table cause its primary key is generator or SEQUENCE object in DB2. How is this configured?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2009 8:30 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Why do u want to have a generator key for join table? And i didnt really understand ur issue. Is it tht you want to configure the mapping so that u get a link table with generator id when the hbm2db is run?

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2009 9:01 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
I think you can achieve this with the <idbag> mapping.

<class name="Parent" table="Parent">
<id name="id" column="ID" unsaved-value="0">
<generator class="native" />
</id>
<property name="name" />
.......
.......
<idbag name="children" table="ParentChild" lazy="false" cascade="all">
<collection-id type="long" column="PAR_CHD_ID">
<generator class="sequence"/>
</collection-id>
<key column="PAR_ID"/>
<many-to-many class="Child" column="CHILD_ID"/>
</idbag>
</class>

_________________
Regards,
Litty Preeth


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.