• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question about transactions (CMT). Am I wrong in understanding "Transactions" at all?

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Olexiy Prokhorenko
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Olexiy Prokhorenko
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!..

Thanks! For everybody :-)
 
reply
    Bookmark Topic Watch Topic
  • New Topic