[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-511) reattach object from same session

HECTOR JUAREZ (JIRA) noreply at atlassian.com
Mon Mar 19 22:32:10 EDT 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-511?page=comments#action_26482 ] 

HECTOR JUAREZ commented on HHH-511:
-----------------------------------

Hibernate version: 3.1.3

Hi, I thinks this issue is related to another one:
When occurs an exception in a transactional method, the Hibernate session associated seems to be cleared, then when is executed another method with the same session and it tries to save an object that was in the session after the exception ocurrencie, the following exception is triggered: "org.springframework.orm.hibernate3.HibernateSystemException: Found two representations of same collection: org.appfuse.model.User.roles; nested exception is org.hibernate.HibernateException: Found two representations of same collection: <<collectionName>> "

For example:
BeanA
method {
User u = UserDao.getUser(1l);
 for (int i=0;i<=1;i++) {
    try {
         beanB.transactionalMethod(u);
    }catch (RuntimeException e) { System.err.println("RuntimeException ="+e);}
  }
}

BeanB
transactionalMethod(User u) {
   ...
   userDao.save(u);
} 

Assuming that BeanA.method and BeanB.transactionalMethod are transactional and they are using the same Hibernate session, if an exception is triggered in the first call to transactionalMethod, then in the second call that method an exception will be triggered in userDao.save(u).
This exception is the commented above, and it happens because in the first method the hibernate session is cleared at the moment of the rollback, so it seems to have no entities and collections associated, but the exceptions is telling us another thing. This seems contradictory and it looks like Hibernate is not handling correctly this situation.
I was able to avoid this exeptions using session.refresh(u) before saving the user object, but I think that Hibernate should be handling this transparently.

Thanks.


> reattach object from same session
> ---------------------------------
>
>          Key: HHH-511
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-511
>      Project: Hibernate3
>         Type: Bug

>   Components: core
>     Reporter: Gavin King
>     Priority: Minor
>  Attachments: reattach-same-session.patch, reattach-same-session.patch
>
>
> http://forum.hibernate.org/viewtopic.php?p=2231400#2231400
> There is a problem when you reattach a collection to the same session that it was previously attached to, after calling clear(). Hibernate checks the collections session reference, at reattach and concludes it is  already attached.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list