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