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.
|
|