Feb 2nd, 2007, 11:21 AM
EJBs and transaction management
I am trying to create a MDB which uses spring-managed hibernate in the course of processing a message. I would like to have the entire process wrapped in a transaction so that if the processing fails, the message is not received and will be resent.
So I originally set my MDB to have Container-managed transactions and I configured the spring JtaTransactionManager just as I had in my web layer. The result was that the bean blew up on initialization because the java:comp/UserTransaction was not available during ejbCreate().
OK, so now I am thinking that that was a bad idea -- I don't need the JtaTransactionManager if I have Container managed transactions. Of course the container didn't make the UserTransaction available, I did not ask it to.
So my current approach is to NOT configure a transaction manager via Spring, but just use the container managed transactions. Is this approach in the sense that it will accomplish what I want? Even if it is correct, is there a better Spring-oriented approach?
Feb 2nd, 2007, 12:06 PM
It depends on what other resources you include in your transaction. If you are only writing to a database, but want to make sure you don't lose any messages in the queue you still don't have to use JTA. Take a look at this article. It describes how to get rid of JTA from an MDB and still guarentee that a message gets delivered exactly once.
Feb 2nd, 2007, 12:17 PM
Thanks interesting read. However, I'm not trying to get rid of JTA, just trying to make sure I have everything configured properly.
Originally Posted by wpoitras
Feb 2nd, 2007, 12:49 PM
My point about getting rid of JTA falls into the "a better Spring-oriented approach". JTA tends to be slow, and really shouldn't be used it its not needed.
You can instead use the HibernateTransactionManager and use BMT. You just need to solve the issues brought up in that article, which mentions how to do it.
But using CMP with Spring should work fine. Its certainly the simplest approach. Just not the best performing.
Feb 2nd, 2007, 01:16 PM
Ah, I see where you are coming from now.