• 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

Stateful Session beans Transaction Boundaries

 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Just taking a look into EJB transactions.

Could someone confirm/deny my basic assumption thank you.

From what I've read in container managed transactions the EJBObject issues a commit (if the method is transactional)when you return from the container.

If this is true, does this mean if you want a transaction boundary to span multiple methods calls to a stateful session bean you are forced to use bean managed transactions or client initiated transactions?

TIA Graham

[ February 20, 2005: Message edited by: Graham VMead ]

[ February 20, 2005: Message edited by: Graham VMead ]
[ February 20, 2005: Message edited by: Graham VMead ]
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've always avoided stateful session beans, but I believe they should provide a serializable Handle that you could pass to another session bean method that had transaction demarcation and called the multiple SFSB methods after looking it up using the passed-in Handle.

Of course, that's for an existing SFSB. Any bean could simply create the SFSB, call multiple methods, remove the bean, and finally return from the transactional method. SFSBs and SLSBs aren't any different in this regard.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Graham,

yes - your basic assumptions are correct.

However, in general, you *don't* want to use long running transactions iniitated by clients, since you need to develop a lot of additional logic to account for cleanup of transactions that never complete, and compensating transactions for things that you've gone ahead and commited and need to roll back. Even worse, if you implement your long running transactions as locking the resources that they're working with, you produce resource contention, which will either lock out other transactions or possibly even produce deadlocks.

So you should never use long running transactions for shared resources.

A bettter approach generally is to put a Stateless Session Bean Facade over the business methods that you want to all be executed as a single transaction, and have this SSB demarcate the transaction boundaries (use Required or RequiresNew), and have it pass it's transactional context on to the other Session (and/or Entity beans) it calls. - i.e. using a short-lived transaction. Otherwise execute the multiple steps as separate transactions and allow for sompensating 'undo' transactions.

cheers,

Dave
 
Graham VMead
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies and your time

Graham.
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic