Question

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?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top