-->
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.  [ 1 post ] 
Author Message
 Post subject: question about transactions
PostPosted: Fri Oct 13, 2006 1:53 pm 
Beginner
Beginner

Joined: Thu Jul 06, 2006 11:09 pm
Posts: 25
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.


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

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.