-->
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: "Found two representations of same collection"
PostPosted: Wed Jun 09, 2004 7:27 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
In my current project our team got the following HibernateException "Found two representations of same collection". Could anybody clear me the cause of this exception?

I see the comment to the method that throws this exception:
Code:
/**
* Initialize the role of the collection.
*
* The CollectionEntry.reached stuff is just to detect any silly users who set up
* circular or shared references between/to collections.
*/
void updateReachableCollection(PersistentCollection coll, Type type, Object owner) throws HibernateException {

   CollectionEntry ce = getCollectionEntry(coll);
      
   if (ce==null) {
      // refer to comment in addCollection()
      throw new HibernateException("Found two representations of same collection");
   }
...
}


Does it mean that an object has two collections with the same JVM idenity or only two equal collections?

Before refactoring everything was fine :). Now going to dig hiberante sources and look what is wrong with our model/logic, but any explanation could help a lot.

Thanks,
one of the silly users (Leonid:)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 10, 2004 7:22 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
answers:

First-level cache (session cache) is implemented using
net.sf.hibernate.util.IdentityMap
Code:
SessionImpl(...)
{
...
    entityEntries = IdentityMap.instantiateSequenced(50);
    collectionEntries = IdentityMap.instantiateSequenced(30);
...}


In the project I found the code similar to the following pseudo-code:
Code:
MyClass obj = (MyClass) session.load(MyClass, id);
// do smth with obj
session.saveOrUpdate(obj); // ERROR!


Solution is obvious: don't do inside one Session session.saveOrUpdate(obj) after the obj was put into the session cache (in my case it was put there by session.load(...)). And session.cear() or session.evict(obj) could help too.

--
Leonid


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.