-->
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 Dec 05, 2007 5:59 pm 
Newbie

Joined: Tue Jun 21, 2005 6:52 pm
Posts: 4
Hi All,

I am getting this error and unable to resolve it. I found that there is a JIRA for this: http://opensource.atlassian.com/project ... se/HHH-511

and the JIRA says that it was resolved in 3.2, but I am not sure why we get this error. There was a patch for this posted by Rodrigo which says the following:


Quote:
Rodrigo S. de Castro - [08/Aug/06 03:00 PM ]
Patch against Hibernate 3.1.3

Apply it with: patch -p1 -i ./reattach-same-session.patch

I developed this patch to fix two problems I faced when reattaching objects to the session after clearing it:

- "reassociated object has dirty collection reference"
- "Found two representations of same collection: (collection type)"

This patch fixes this problem by allowing an object from a given session to be reattached. To do that, there are two minor changes in two classes:

- OnLockVisitor: in processCollection(), when a collection has been attached to the same session, we only throw an exception if the collection is dirty, otherwise we reattach this collection to the session and move on.

- Collections: in processReachableCollection() method, when a given collection is not found in the session persistence context, we check if it is a collection that has been previously attached to the session. If it is, we add this collection back to the persistence context. That fixes "Found two representations..." problem.


I am not sure whether the patch went into 3.2, but I see that the code for Collections still shows this from 3.2.5.ga:

Code:
public static void processReachableCollection(PersistentCollection collection, CollectionType type, Object entity, SessionImplementor session)
        throws HibernateException
    {
        collection.setOwner(entity);
        CollectionEntry ce = session.getPersistenceContext().getCollectionEntry(collection);
        [b]if(ce == null)
            throw new HibernateException("Found two representations of same collection: " + type.getRole());[/b]        if(ce.isReached())
            throw new HibernateException("Found shared references to a collection: " + type.getRole());
        ce.setReached(true);
        SessionFactoryImplementor factory = session.getFactory();
        CollectionPersister persister = factory.getCollectionPersister(type.getRole());
        ce.setCurrentPersister(persister);
        ce.setCurrentKey(type.getKeyOfOwner(entity, session));
        if(log.isDebugEnabled())
            log.debug("Collection found: " + MessageHelper.collectionInfoString(persister, ce.getCurrentKey(), factory) + ", was: " + MessageHelper.collectionInfoString(ce.getLoadedPersister(), ce.getLoadedKey(), factory) + (collection.wasInitialized() ? " (initialized)" : " (uninitialized)"));
        prepareCollectionForUpdate(collection, ce, session.getEntityMode(), factory);
    }


As shown by the code, in processReachableCollection(), if the CollectionEntry is not found in the PersistentContext, the "Found two representations of same collection:..." HibernateException is thrown.

I am not an expert in Hibernate. I would really appreciate if anyone can let me know the cause and solution to this problem.

Thanks,
S


Top
 Profile  
 
 Post subject: Same problem: Found two representations of same collection
PostPosted: Sat Feb 02, 2008 11:30 pm 
Newbie

Joined: Sat Feb 02, 2008 11:21 pm
Posts: 1
Hi,

I am also getting the same problem. But my environment is totally different.
I use Hibernate 3.2.5.ga in a desktop product. It is multi threaded. Session.clear() is never used.

There are around 3 thread and all use the same Session. But all session access was locked. So only one thread will be using session at any point of time.

May be mine will the first commercial application using Hibernate in a desktop product in such an environment. Everything is working fine, except this HibernateException..

"Found two representations of the same collection".

Session.clear() is never used. not only that, only methods we have used in Session are save(), saveorUpdate(), load()

Even Session.delete() is never used.

And more worse is that the problem is coming randomly at different collections.

Can any one suggest me, where to look?

Thank you
Rajesh Akkineni


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.