-->
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: Session finalization issues
PostPosted: Fri Jan 28, 2005 11:35 am 
Newbie

Joined: Sat Jun 26, 2004 11:14 am
Posts: 6
I am using Hibernate version 2.1.7c.

I am using the session-per-transaction pattern with a CMT bean.


I am load testing the application and have the following code executing in a non-transactional bean.

Code:
while (!done && tries<MAX_TRIES) {
  try {
        transactionalBean.persist( container.getCurrentState() );
        done = true;
    } catch (RuntimeException e1) {
        if (isDeadlockException(e1)) {
          LogFactory.getLog(this.getClass()).error("Retrying after Deadlock("+tries+")", e1);
          tries++;
        } else {
            throw e1;
        }
    }
}


I get the following error intermittently:

Caused by: net.sf.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at net.sf.hibernate.collection.PersistentCollection.setCurrentSession(PersistentCollection.java:257)
at net.sf.hibernate.impl.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:38)
at net.sf.hibernate.impl.AbstractVisitor.processValue(AbstractVisitor.java:69)
at net.sf.hibernate.impl.AbstractVisitor.processValues(AbstractVisitor.java:36)
at net.sf.hibernate.impl.AbstractVisitor.process(AbstractVisitor.java:91)
at net.sf.hibernate.impl.SessionImpl.doUpdateMutable(SessionImpl.java:1465)
at net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1479)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1402)
at gigo.database.hibernate.HibernateDatabase.saveOrUpdate(HibernateDatabase.java:91)


I have similar code executing from the web container and never see this exception.

It seems that when the CMT transaction is rolled back, the session is not finalized before the exception reaches the client and the second session is created.

Is there a way for me to ensure that the first session is destroyed before I raise the exception from the transactional method?


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.