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.  [ 8 posts ] 
Author Message
 Post subject: ***hbm file for link table many-to-many***
PostPosted: Tue Aug 26, 2008 5:47 am 
Newbie

Joined: Tue Jun 10, 2008 12:39 pm
Posts: 14
Hi,

I want to create a .hbm.xml file for many-to-many link table
because whenever there is some deletion of the row in the link table
the child tables of the link table must also cascade the delete.

eg:

Tables A And B have many-to-many relation.

The link table is A_B;this link table has a child table A_B_child;

now whenever arow is deleted in the link table A_B i should cascade it in A_B_child.

the link table has got two foreign keys from table A and table B.

can u please explain me how to create a .hbm file for link table and use cascade to its childs.

can u please respond quickly.

Babu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 26, 2008 3:21 pm 
Newbie

Joined: Fri Aug 22, 2008 4:07 pm
Posts: 9
It looks like this has been discussed before.

Does this link help?:
http://forum.hibernate.org/viewtopic.ph ... 4d5cf9b871


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 7:31 am 
Newbie

Joined: Tue Jun 10, 2008 12:39 pm
Posts: 14
No its completely different reference u have given.
Please check my question again.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 10:09 am 
Newbie

Joined: Fri Aug 22, 2008 4:07 pm
Posts: 9
I guess I am not understanding the problem then. Could you provide your existing configuration (hbm.xml) files, and an example of what you are trying to do?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2008 5:14 am 
Newbie

Joined: Tue Jun 10, 2008 12:39 pm
Posts: 14
Table 1:

Name : Account
Columns: account_id
account_name

Table 2:


Name: Field
Columns : field_id
field_name

Account and Field => many-to-many association

link table:

name : account_field
columns : account_id
field_id


Link Table(account_field) has got a child account_field_child

Link Table Child :

Name : account_field_child
Columns :account_id
field_id
account_field_childname
account_field_childdescription

Queries :


1) Do I need to go for a .hbm.xml for the link table;because I need to cascade delete the account_field_child whenever a row is deleted in account_field.

2)I want to maintain unidirectional many-to-many relationship from account to field;so how to cofigure <set> in Account to specify link table in this scenario.

Thanks
Babu[/code][/list]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2008 5:51 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Quote:
1) Do I need to go for a .hbm.xml for the link table;because I need to cascade delete the account_field_child whenever a row is deleted in account_field.


Yes, you have to model the link as an entity. Then you need a one-to-many association from Account to AccountField and a many-to-one from AccountField to Field. Additionally you can setup an one-to-one association from AccountField to AccoutFieldChild (or whatever you need here).

Quote:
2)I want to maintain unidirectional many-to-many relationship from account to field;so how to cofigure <set> in Account to specify link table in this scenario.


Somthing like that:

Account:
Code:
<set name="AccountFields">
  <key column="account_id"/>
  <one-to-many class="AccountField" .../>
</set>


AccountField:
Code:
<many-to-one name="Field" class="Field" column="field_id"/>


[/quote]

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 29, 2008 5:15 am 
Newbie

Joined: Tue Jun 10, 2008 12:39 pm
Posts: 14
Thank You Wolli.


Last edited by sureshaverineni on Fri Aug 29, 2008 5:19 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 29, 2008 5:16 am 
Newbie

Joined: Tue Jun 10, 2008 12:39 pm
Posts: 14
Thank You Wolli...This is working for me.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.