-->
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: Problem: same identifier value was already associated
PostPosted: Tue May 11, 2004 4:52 pm 
Beginner
Beginner

Joined: Tue May 11, 2004 10:40 am
Posts: 37
Location: Belgium
When I implement the composite pattern, hibernate gives the following error:

net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 0, of class: logic.StdComposite


I read on the Hibernate site:(http://www.hibernate.org/117.html?cmd=prntdoc)
Quote:
Hibernate throws: Another object was associated with this id
For a particular session, there may be at most one object that represents a particular database row. So, if you already loaded an object with a particular identifier, you can't then try to associate a different object with the same identifier by calling update().

If you absolutely must do this, evict() the original instance first - but it is much better to simply avoid this situation.

But how is it possible then to implement the composite pattern?

For example:
Component c1 = new Component(...);
Component c2 = new Component(...);
c1.add(c2); //for example: c2 is the child of c1, but the objects c1 and c2 have the same class types and will be stored in the same table.

Why does hibernate not automatically assign different id's for the two objects?

How can I solve this problem?

Thanx in advance...
Stijn.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 5:03 am 
Regular
Regular

Joined: Wed May 12, 2004 3:03 am
Posts: 51
Location: France
Hi,

Could you please give the java code ?

Charles


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.