This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
In my application, I have 2 session stateless beans. I am using CMT. One of beans have method zzz(), which has RequiresNew transaction attribute, and this method calls other's bean's methods hello1() and hello2(), which has Required transaction attribute (both of them). These two hello*() methods do some calculations, output some debug information, and return java.lang.String values.
This is what I have in logs:
So, what's my question is about. :-) Method hello2() has at the end of it's calculations ctx.setRollbackOnly(). And this means that everything NEED to be roll-back. But as far as they are doing there calcuations, returns values, do debug output -- Where Is The Roll Back???
May be I am doing something wrong?
I am using BEA WebLogic 8.1, and my ejb-jar.xml seems to look properly configured, here it is:
Please, advice something. May be I am wrong in my understanding transactions? :-) [ October 04, 2004: Message edited by: Olexiy Prokhorenko ]
<a href="http://www.BossTalks.com" target="_blank" rel="nofollow">http://www.BossTalks.com</a><br />Free advices and help for entrepreneurs: from Idea to IPO<br />Software and IT Project Management forum
It sounds like you are understanding the concept of transactions just fine. The problem is in assuming that everything you're doing is transactional, which it's not.
When you use CMT, the container (WebLogic in this case) makes use of JTA (Java Transaction API) to manage and enlist resources in the transaction -- things like databases and message queues. Method calls themselves, logging, and return values are not transactional resources.
Note that it would be possible to create a logging library that was transactional, but typically you want a message logged whether or not the transaction is committed.
To test this out, you can perform data-modification actions through a JTA-capable JDBC Connection and see that they are rolled back appropriately.
Joined: Jul 11, 2004
Thanks for your reply! I though something like you are saying, too. I decided to test transactions with CMP entity bean.
I've tried my stuff with CMP entity bean, and you know what? Even if everything looks pretty correct, rollback still doesn't work!
Well, here it is piece of my ejb-jar.xml:
So, this works the following way. SessBean1.zzz() executes create() on EntBean1 and this really creates record in database (I am using MySQL). Then, SessBean1.zzz() calls SessBean2.hello1(). It does some calculations, and at the end of this method ctx.setRollbackOnly() is called. As we can see in my debug logs:
Everything changes as it should. Exactly after SessBean2.hello1() runs setRollbackOnly(), SessBean1.zzz() "see" that absolutely correctly!!!
But why really record in database stay "alive", and didn't roll back? Am I missing something important?
Joined: Jul 11, 2004
Solved. It's not about me being stupid in EJB, but it's about me losing tiny facts. MySQL has MyISAM table's type by default, but it also does not support transactions. We need InnoDB for transactions, and that was why everything was not working!..