liem wrote:
Well, even though I am running on JBoss 3.2.5 (yeah, old), but I am accessing Hibernate from both MBeans and EJB. EJB works fine (well, sort of, reason later), but MBeans obviously don't run in the context of a JTA (is there a way to make them? I am new to MBeans).
So, currently, I am resorting to the Session-in-ThreadLocal pattern to handle my sessions, rather than using getCurrentSession(). We don't have any inter-bean transaction, so I think this should be fine.
One question, though, I am running into the problem of my EJB not rollingback as expected. For example:
ejb1Method {
save();
query();
update();
}
I declare the above method as using CMT and "RequiresNew". But, if query() fails (and throws an uncaught RuntimeException to the container), save() still succeeds and the data makes its way into the database. I expect the save() to be rolled back and nothing gets saved into the database unless the entire ejb1Method() suceeds?!? BTW, I am using the "FlushBeforeCompletionEnabled" and "AutoCloseSessionEnabled" set to true.
Anyone ran into this CMT not rolling back correctly problem? Hibernate used is 3.0.4.
Thanks in advance,
Liem
So, from my understanding, the 'FlushBeforeCompletionEnabled' and 'AutoCloseSessionEnabled' attributes are specifically for the getCurrentSession() method, I don't think it works with the threadlocal pattern.
And in the EJB annotations, I specified the transaction type as "Required". It should work ..
Are you specifying the transaction manager and transaction manager lookup class in your hibernate.cfg.xml ?