-->
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.  [ 4 posts ] 
Author Message
 Post subject: Bi-directional Mapping
PostPosted: Fri May 25, 2007 6:33 am 
Newbie

Joined: Fri May 25, 2007 6:06 am
Posts: 3
Hello,

I am trying to maintain the following model described below. I am going to describe it in high level terms as I would like an example of how to map it. I have looked in the hibernate forum and been using the Hibernate In Action book, however I'm still confused.

Model:

I have a User object which holds a collection of codes. Codes may be added and removed from the user's code collection as necessary.

Each code object holds a collection of users. Users may be added and removed from the code as necessary.

Each collection as mapped with a set, using a many to many association. What I'm finding is that when I modify the collection in one object, the other side of the association is not updated. I.e. when I add a code to a particular user, that user is not then visible in the code's collection.

Mappings:

user object's code collection:

<set name="adminCodes" table="ADMIN_CODE_REL" inverse="false" lazy="false" sort="natural">
<cache usage="read-write" region="domain.entity.USER_REGION"/>
<key column="ADMINISTRATOR_ID"/>
<many-to-many column="CODE_ID" class="domain.entity.attribute.CustomCode" where="MARK_FOR_DELETE=0" />
</set>

code object's user collection:

<set name="administrators" table="ADMIN_CODE_REL" inverse="false" lazy="false" sort="natural" batch-size="50" >
<cache usage="read-write" region="domain.entity.USER_REGION"/>
<key column="CODE_ID"/>
<many-to-many column="ADMINISTRATOR_ID" class="domain.entity.Administrator" where="MARK_FOR_DELETE=0 AND USER_TYPE=1" />
</set>


What I'm interested in is an example that will show me how to use the inverse attribute correctly, and any cascade styles, if necessary.

Thanks,

Jason.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 6:38 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi J4S0N,

Read This

http://simoes.org/docs/hibernate-2.1/155.html

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 7:00 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

Use inverse in parent. but in here there is no such a paren. so use inverse='true' in one of a set.


Parent is responsible of the relationship. Hibernate insert parent, insert child then update the relationship (as a request to the parent). Two SQL orders are executed (one insert and one update) instead of one.


Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 8:55 am 
Newbie

Joined: Fri May 25, 2007 6:06 am
Posts: 3
Thanks for your replies. I reread the 'bi-directional many to many' section in 'Hibernate In Action' and used the examples in there. Basically I had inverse and cascade attributes defined all wrong.

Thanks again for the quick reply tho, it made stop and read the instructions properly :-D


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