-->
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.  [ 3 posts ] 
Author Message
 Post subject: Please explain this behavior of session
PostPosted: Sat Jun 21, 2008 12:34 pm 
Newbie

Joined: Sat Jun 21, 2008 12:16 pm
Posts: 3
I could understand the following behavior of the session when i wrote some code to experiment with session's transactions. I listed my scenarios #2 is the actual question.

1)First i got session using sessionfactory.opensession() and with out beginning a transaction i saved a entity and then flushed and closed the session , obviously the data is not persisted and cannot be seen outside this code (transaction). Code looked like this

session = sessionFactory.openSession()
session.save(myObject);
session.flush();
session.close();

2) Then i did this.
session1 = sessionFactory.openSession()
session1.save(myObject);
session1.flush();
session1.close();

session2 = sessionFactory.openSession();
session2.beginTransaction();
session2.save(myObject2);
session2.getTransaction().commit();

Then both myObject and myObject2 got persisted. why did session1 got committed even tho it was closed before the transaction began on session2. Strangely they both use same connection object. I am using hsqldb as the database

Thanks in advance.


Top
 Profile  
 
 Post subject: The link explains it
PostPosted: Sat Jun 21, 2008 10:06 pm 
Newbie

Joined: Sat Jun 21, 2008 9:59 pm
Posts: 1
http://www.hibernate.org/403.html


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 22, 2008 5:00 pm 
Newbie

Joined: Sat Jun 21, 2008 12:16 pm
Posts: 3
Thanks!
I figured that its because hibernate has its own connection pooling and was returning the same connection for which autocommit was disabled earlier and there are pending transactions on it.
They got committed with next commit command on the connection object.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.