Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
[b]Hibernate version:3.1.1[/b]
Read this:
http://hibernate.org/42.html
Hi all,
I have a problem regarding the using of the same Hibernate session across transactional methods.
I thinks this issue is related to another one posted in Jira: "HHH-511"
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 exceptions using session.refresh(u) before saving the user object, but I think that Hibernate should be handling this transparently.
Anybody Know something regarding this issue?
Any ideas will be very helpful.
Thanks to all.