-->
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.  [ 6 posts ] 
Author Message
 Post subject: many-2-many relationship
PostPosted: Tue Apr 06, 2004 7:34 am 
Beginner
Beginner

Joined: Thu Feb 26, 2004 6:59 am
Posts: 47
Location: Gurgaon, India
Hello,

I want to implement a many-to-many relationship.

Like I have a User object and a UserGroup object. Both has many-to -many relation. Now what did I do:

Made a java class for User, with a setter for UserGroups as set
Made a java class for UserGroup

give mapping for UserGroups set in User mapping file like :

<set name="UserGroups" table="User_Groups" cascade="all" inverse="true" lazy="true">
<key column="User_id"/>
<many-to-many class="com.a.b.UserGroup">
<column name="UserGroup_Id"/>
</many-to-many>
</set>

Now, I made new objects of User and Set userGroups object to this object. I saved it.

As a result, I got records in User table and as well as in UserGroup table, but there I found no record in User_Groups table. I was expecting it, as relation table should be filled by itself by hibernate.

Am I wrong in this scenerio, Please guid me for it. It is urgent

Thanks,

_________________
Mohit Gupta
Software Engineer
Gurgaon, India


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 6:53 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://www.hibernate.org/155.html

_________________
Emmanuel


Top
 Profile  
 
 Post subject: this is not a solution
PostPosted: Wed Apr 07, 2004 8:08 am 
Newbie

Joined: Tue Apr 06, 2004 4:36 pm
Posts: 2
I have the same problem.

even if the inverse thing is set correctly and the many-to-many is bidrectional ( with one inverse=true, and one inverse=false ) it simply wont add entries to the collection table (aka the mapping table).

I even have a one-to-one copy of the example from chapter 18 ( the one with the works and authors: http://www.hibernate.org/hib_docs/refer ... mples.html ) - it simply does not work.

is there anything special, in version 2.1?

please help!
-- Jakob


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 8:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
(1) Did you add objects to both sides of the association?
(2) Did you flush the session?

Quote:
it simply does not work


Please express yourself better in future, of course it works, you are using it wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 8:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
(1) Did you add objects to both sides of the association?
(2) Did you flush the session?

Quote:
it simply does not work


Please express yourself better in future, of course it works, you are using it wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 15, 2004 2:27 am 
Beginner
Beginner

Joined: Thu Feb 26, 2004 6:59 am
Posts: 47
Location: Gurgaon, India
Jakob,

<set name="categories" table="catalog_category" cascade="all-delete-orphan" lazy="true">
<key column="catalog_id"/>
<many-to-many class="com.aceva.rms.catalog.Category">
<column name="category_id"/>
</many-to-many>
</set>

This mapping is working fine.

Gavin,

Thanks, and will try to explain problems in some better way.


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