EJB transaction rollback with hibernate

932 views Asked by At

So I'm using container managed transactions in OpenEJB and Hibernate and I have a fairly simple transaction rollback scenario I'm trying to get to work. My DBMS is MySQL.

I start off with a stateless EJB that has default transaction propagation (required) that performs some basic entity manipulation / creation.

I also have a second stateless EJB that has an annotation for specified propagation (but it's still just 'required'). From this second EJB method, I call the first EJB's method that does that basic entity manipulation / creation. I get back an entity that does not yet have an ID, so I called entityManager.flush(), which gives me an ID to work with on my entity returned from that first EJB.

Here's where I get a problem. That second EJB now has a problem, be it a System Exception, or some kind of exception. I'd like to force a rollback, so this EJB has a @Resource SessionContext ctx member that I use to call ctx.setRollbackOnly().

This is what I see in the log:

DEBUG - TX Required: Started transaction org.apache.geronimo.transaction.manager.TransactionImpl@540eb4ca

....stuff, eventually stack trace I'm logging....

DEBUG - TX Required: setRollbackOnly() on transaction org.apache.geronimo.transaction.manager.TransactionImpl@540eb4ca
DEBUG - TX Required: Rolling back transaction org.apache.geronimo.transaction.manager.TransactionImpl@540eb4ca

But when I check the database, the changes from the first EJB are still in the database. What am I missing?

1

There are 1 answers

1
axtavt On BEST ANSWER

Perhaps you use MyISAM as a storage engine for your table. It doesn't support transactions, use InnoDB instead.