• 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

About setRollbackOnly method in a transaction

 
Bartender
Posts: 2419
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On p.177 of EJB in Action,


The setRollbackOnly mehtod on the EJBContext can only be used in methods that have a transaction attribute type of REQUIRE, REQUIRED_NEW or MANDATORY. If a transactions hasn't been started, as in the case of SUPPORTED or NEVER, a java.lang.IllegalStateException will be thrown.



What about this case ?
A method is annotated with a transaction attribute type of SUPPORT. And this method will join an existing transaction. Can we roll back changes in this method ? I assume we cannot roll back changes in such a method, based on this quote. Then, is it possible to roll back any changes?
 
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The specs say

Only enterprise beans that will execute correctly in both modes should use the SUPPORTS transaction attribute.


You can't guarantee that the method will be called with a transaction present so you wouldn't know when to do the rollback and when not to. If a transaction exists it will probably work because the specs only say the exception is thrown if "the instance is not allowed to use this method (i.e. the instance is of a bean with bean-managed transactions)." but it will be very bad practice to use transaction semantics in a method marked as SUPPORTS.
 
Himai Minh
Bartender
Posts: 2419
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply.
So, using the placeOrder() method in the EJB in Action as an example:
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whether it will throw an exception or not could be implementation specific. The API specs don't explicitly say what will happen. The code is a contradiction. It declares that the method doesn't care about the presence of a transaction and yet it goes on to try and use it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic