• 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

Websphere transactions

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

I am testing transactions in WAS 5.0 and It does not work as expected.
I have one Session Bean and three Entity Beans. Method reserve() in Session Bean has transaction attribute REQUIRED and calls methods in three other Entity Beans. When no Exception occurs all works fine - data is written to all three tables.
But if I intentionally throw an exception after calling first Entity Bean the data is written to the first table - but it shouldn't - all operations on Entity Beans are in one transaction.

Rafaello
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm, that does sound odd. Off hand your set up sounds right, is it possible you're catching the exception before it has a chance to reach the container?

The server should, once it sees the exception, trigger a rollback on the entire transaction, so I'd examine your database settings on the container in more detail.

The only work-around you can do is catch the exception inside the highest level of the bean, manually request a rollback on the persistence manager, then rethrow the exception so something still goes to the container. There is actually an advantage to doing this in that you can catch/recover optimistic locking errors that are normally not recoverable. Normally such errors are only checked after the container is finished and then must be recovered by a delegate.
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mention the transaction attribute of the Session Bean but not the transaction attributes of the Entity Beans. Could you share them with us? I guess that your entity beans are CMTs. Could you confirm that? And what kind of transaction is being thrown? Only certain type of transactions will make the container to automatically rollback the transaction.

Regards
Paulo
 
Jorge Ribeiro
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As you can guess, my last two phrases are incorrect. Here goes the corrected version:

And what kind of exception is being thrown? Only certain type of exceptions (system exceptions) will make the container to automatically rollback the transaction.
 
Scott Selikoff
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a quick tip, you can edit posts after you write them by clicking the edit button within the post.

Aside from that, I thought all uncaught exceptions that made it to the container level trigger the rollback? If not, then there's the answer. If you wanted it to trigger a rollback you'd have to catch it and re-throw it as something more serious that would trigger the rollback.
 
author
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul is correct, application exceptions do not trigger a rollback. You can catch the application exception and do a setRollbackOnly or rethrow an EJBException. CMP by default are usually REQUIRED and use CMT.
[ November 16, 2005: Message edited by: Roland Barcia ]
 
Rafaello Stern
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I cought the exception and setRollbackOnly and now it works fine.
Transaction attributes of Entity Beans are REQUIRED.

Thank you.

Rafaello.
 
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic