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
|