-->
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: Synchronization only called on commit, not rollback
PostPosted: Mon Aug 09, 2004 11:05 am 
Newbie

Joined: Mon Aug 09, 2004 10:28 am
Posts: 4
Location: Sweden
In my setup I am using Websphere 5 and stateless EJBs for declarative transaction demarcation.
I use the WebsphereTransactionManagerLookup-class to associate with the CMT.

I am trying to get away from the following tedious (and error-prone) method-template :

Session s = HibernateUtil.currentSession();
try {
...
s.flush();
...
finally {
s.close();
}


Instead I am using the TransactionManager and registerSyncronization() so that my sessions
will implicitly be flushed and closed whenever the transaction is completed.
My new methods look like this:


Session s = HibernateUtil.currentSession();
...


and the registered synchronizer contains the method:


public void beforeCompletion() {
log(...);
flushSession();
closeSession();
}



The setup above works fine when the transaction went OK and is commited. I also see a message written to the log.

However, when the transaction is rolled back, it seems as though the synchronizer is never called.
Not beforeCompletion() and not afterCompletion(). No message is written to the log.

Is this a known problem?

Is it a problem at all - nothing saved on a rollback should be pretty OK..?
My only worry is that Session.close() is never called, or maybe Hibernate and Websphere can handle this? `


Perhaps someone even has a better solution to the problem I am trying to solve?
And I know about the Spring-solution... but is there another way?


/Tobbe


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 09, 2004 12:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Well if you ever get it working, on failed transaction you should *not* flush the session; just close it.

If your synch is not failed on application rollback, then that would be a very ugly bug in websphere.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 3:13 am 
Newbie

Joined: Mon Aug 09, 2004 10:28 am
Posts: 4
Location: Sweden
OK, it seems the docs are not quite accurate. They state:

public void beforeCompletion()
This method is called by the transaction manager prior to the start of the transaction completion process.

Well, it is actually only called before a commit.
The afterCompletion() is always called though (my mistake...)
My new Synchronization implementation looks like:


public void beforeCompletion() {
flushSession();
}

public void afterCompletion(int status) {
closeSession();
}


This should be what I want and what Hibernate want.
Thanks for poiting that out!


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.