-->
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.  [ 1 post ] 
Author Message
 Post subject: JPA exception: Found two representations of same collection
PostPosted: Tue Sep 29, 2009 9:10 am 
Newbie

Joined: Sat Sep 26, 2009 12:00 pm
Posts: 6
Hi all.

I admit defeat on my preivous attempt at getting an answer to a question here on the Hibernate Users forum (viewtopic.php?f=1&t=999915&start=0).
I can only assume that the reason why I did not get any answers to my troubles was that I did not clearly explain my question, so I shall try to do better job now.
______________________________________


I have a J2SE application where I use JPA with Hibernate as persistence provider. The versions of the required hibernate jars that I use are:
hibernate3.jar (3.3.2.GA)
hibernate-annotations.jar (3.4.0.GA)
hibernate-commons-annotations.jar (3.1.0.GA)
hibernate-entitymanager.jar (3.4.0.GA)

I have an entity where i have a bidirectional One-To-Many mapping. This is initialized to an empty list, something that clearly is allowed according to the JPA 1.0 spec.

i.e. I have:
Code:
in class Parent:

@OneToMany(mappedBy="parent", cascade = CascadeType.ALL)
private List<Child> children = ArrayList<Child>();

class Child:

@ManyToOne
@JoinColumn(name="PARENT_ID")
private Parent parent;


A certain sequence of actions result in a HibernateException being thrown (wrapped by JPA in a RollbackException):
  • Obtain a new EntityManager
  • Begin a transaction
  • Fetch a Parent entity from the entity manager (this exists in the db), call this e.
  • Apply an EntityManager.remove() on e
  • Commit the transaction
  • Begin a transaction
  • Apply an EntityManager.persist() on e
  • Commit the transaction

The exception is thrown on the last commit():
Code:
Caused by: org.hibernate.HibernateException: Found two representations of same collection: Parent.children
    at org.hibernate.engine.Collections.processReachableCollection(Collections.java:176)
    at org.hibernate.event.def.FlushVisitor.processCollection(FlushVisitor.java:60)
    at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:124)
    ...


Does anyone know why this happens? I have tried to flush(), clear(), and pretty much everything on the entity manager (event fetching the Hibernate Sesssion and clearing this) - the only thing that helps is creating a new one before attempting the last transaction.
Moreover, after some investigation, the persisted entity actually seems to be persisted correctly - despite the exception (this also seems to hold true for any cascaded persists), perhaps the only erroneous thing here is the fact that an exception is thrown when it really should not?

I challenge anyone who knows anything about this issue to please share their thoughts.

-Horat


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.