-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to spawn multiple transactions using a single session?
PostPosted: Wed Mar 29, 2006 3:21 am 
Newbie

Joined: Sun Mar 26, 2006 3:04 pm
Posts: 6
Consider the following piece of code. Here I am trying to open two trnsactions using the same session.

1: Session session = HibernateUtil.getSessionFactory().getCurrentSession();
2: Transaction transaction1=session.beginTransaction();
3: Event e= (Event) session.load(Event.class, id1);
4: transaction1.commit();
5: Transaction transaction2=session.beginTransaction();
6: Event e2= (Event) session.load(Event.class, id2);
7: transaction2.commit();

This gives me an "org.hibernate.SessionException: Session is closed!" error in line 5. So transaction1.commit() is leading to session.close() getting called. Is there any way I can turn off this behavior?

From the hibernate documentation it looks like hibernate has the capability to do this. Discussions on topics like "long conversations" and "optimistic concurrency" (Sec 11.3.2) allude to a single session spawning of multiple transactions, but does not give any code on how this is actually done.

I think there should be some configurable passed on to SessionFactory / Session or Transaction for this behavior to happen. After digging through the documentation I was unable to find any specific mention of this. Any help regarding this would be greatly appreciated.

Thanks
DuKot


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 1:46 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
You need to specify
hibernate.transaction.auto_close_session=false
in the configuration

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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

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.