• 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

CMT supports & getRollbackOnly

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

I'm wondering what happens if i call a business method in a CMT bean that has the transaction behaviour "supports" and I call for example getRollbackOnly:

the spec says(17.6.2.3 Supports):

� If the client calls with a transaction context, the Container performs the same steps as
described in the Required case.
� If the client calls without a transaction context, the Container performs the same steps as
described in the NotSupported case.


would mean:
- with transaction context => works
- without transaction context => IllegalStateException (according to HeadFirstEJB)


how can I handle "supports" as bean provider then ?

Severin
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very good question Severin

Actually, if you look a little further in the spec, section 17.6.2.9 states that:
"The Container must handle the EJBContext.getRollbackOnly() method invoked from a business method executing with the Required, RequiresNew, or Mandatory transaction attribute.
The Container must throw the java.lang.IllegalStateException if the EJBContext. getRollbackOnly() method is invoked from a business method executing with the Supports, NotSupported, or Never transaction attribute."

...which corroborates what HeadFirstEJB says.

In the section you quote (17.6.2.3), there is also a very important note at the end, which is:
"The Supports transaction attribute must be used with caution. This is because of the different transactional semantics provided by the two possible modes of execution. Only the enterprise beans that will execute correctly in both modes should use the Supports transaction attribute."

In case of a business method with a Supports transaction attribute, if the client calls without a meaningful transaction context, the container will throw an IllegalStateException. This is a system level exception, and thus, the container will apply the usual rules for taking care of this (as summarized in Table 15, p. 375, last two rows):
- Log the exception
- Discard the bean instance
- Throw RemoteException to remote clients and EJBException to local clients

Also, it is important to read section 17.6.5 to understand what happens in the case the bean runs within an unspecified transaction context.
 
Severin Stoeckli
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Valentin,

Thank you very much, very good answer. My opinion is, "supports" isn't really useful in practice.

Severin
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My opinion is, "supports" isn't really useful in practice.
I admit I've never used it myself
 
reply
    Bookmark Topic Watch Topic
  • New Topic