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.  [ 2 posts ] 
Author Message
 Post subject: *** Inverse="true" Exact usecase ***
PostPosted: Sun Aug 31, 2008 2:24 pm 
Newbie

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

I have an Account and Detail tables with one-to-many association.

Table 1:

Name : Account
Columns: account_id
account_name

Table 2:

Name: Detail
Columns : detail_id
detail_name

1) Account is having a SET to maintain Details.Detail will be having a reference to Account.I can get the set of Details from Account object.,from the other side I will be getting account object for every Detail Object.

2)In the Account.hbm.xml files :

<set name="detail" cascade="all" lazy="false">
<key column="account_id" not-null="true"/>
<one-to-many class="Detail"/>
</set>

In the Detail.hbm.xml files.

<many-to-one name="account" column="account_id”
class="account" not-null="true" lazy="false" />


3) According to many articles, here I should go for Bi-directional association and make
<many-to-one> inverse=”true”.I should update on bothsides account.setDetails(<set>Detail) and Detail.setAccount(account)

I am not doing the above, still I am able to satisfy the requirement.

Queries :

1) Can u please explain me the use of birectional association instead of going in my way as two unidirectional (one-to-many and many-to-one) associations.

2) I am not updating the both sides of the association at any time.Can u please tell me what is the requirement to do so?

Thanks
Babu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2008 1:19 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
The answers to your questions are all here:

http://www.hibernate.org/hib_docs/nhibe ... child.html

“inverse” doesn’t make your association bidirectional. As soon as you have an association on both sides it's bidirectional. "inverse" only defines the owning end. If you define a bidirectional association without inverse you may run into troubles when detaching objects from a session and maybe other scenarios.

Hope that helps.

_________________
--Wolfgang


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