In Hibernate documentation, it clearly states that transaction.commit() automatically flush() then close()s that current session. And this also applies to UserTransaction JTA environment?
Here's my code:
try {
// UserTransaction looked up from JNDI.
// tx.begin() called.
// session facade started.
// currentSession retrieved from JNDI binded SessionFactory
// program logic is here.
// display result to View.
// facade.flush() (session.flush())
// facade.close() (session.close())
// called session.close()
// tx.commit() called.
} catch (Exception) {
// tx.rollback is here.
// something to do with the exception.
}
The start of this code is fine (in accordance with Hibernate documentation). Session is automatically binded in the current transaction. If, for example, I remove the facade.close() part, I'm getting the Session is close exception in every other request. It means, that the first time I called, do something with the session, then commit, the transaction is successful. But the next time I do the same thing, I get the exception. This cycle repeats itself if I haven't declared the facade.close() which wraps then session.close() method.
Also, if the facade.flush() (wraps session.flush()) is not there, the new values of an entity or when deleting an entity will not be applied to the persistent storage.
I thought that transaction.commit() automatically flush()es and close()es the transaction?
_________________ Don't forget to rate.
|