-->
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: Many to Many with Composite element always deleting
PostPosted: Mon Jun 14, 2004 4:33 pm 
Newbie

Joined: Fri May 14, 2004 5:38 pm
Posts: 12
Hi all..

I am having a strange problem with my many-to-many association.

I have an object 'A' assocaited with object 'B' through object 'AB.'
AB has additional fields, so I have done the mapping as a composite element with a 'many-to-one' element within it.

The strange thing that I have noticed, however, is that when I load Object 'A' and do a trivial operation on the collection (say, for example, A.getB().size()) it works fine, but when the session commits, it deletes all of the associations, and re-inserts them. In fact, it deletes each of my association elements 1 by 1, and then reinserts them...

any ideas?

thanks,

joe


Top
 Profile  
 
 Post subject: I almost understand...
PostPosted: Mon Jun 14, 2004 5:52 pm 
Newbie

Joined: Fri May 14, 2004 5:38 pm
Posts: 12
Okay... so I implemented equals() and hashcode() on my composite element and it seems to have solved the problem... and created a few more questions.

Can someone explain, or point me to a document that explains, why this is necessary? Is it because the composite-element is not a full fleged persistant object, and thus Hibernate does not track it's identity?

Also my class, 'AB' does not have any of the foreign key fields in it. The only fields it has is a property object (in my case a boolean) and a field for 'B' (for the many-to-one). Thus when I implement equals() and hashcode() I only have these two fields to work with. It seems to work, but it doesn't feel like it's the proper thing to do. Should I make sure this composite-element also contains a field that holds the id of it's parent?
(thus, really implementing the databases's idea of identity?)

thanks!

joe


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 6:15 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://www.hibernate.org/109.html is a good material
and the reference guide too.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 7:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No, it is because of the semantics of java.util.Set


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.