Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CMT supports & getRollbackOnly

 
Severin Stoeckli
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • 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
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • 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
  • 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
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My opinion is, "supports" isn't really useful in practice.
I admit I've never used it myself
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic