Forums Register Login

CMT supports & getRollbackOnly

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Valentin,

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

Severin
+Pie Number of slices to send: Send
My opinion is, "supports" isn't really useful in practice.
I admit I've never used it myself
rubbery bacon. crispy tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1011 times.
Similar Threads
Exception when Transaction attribute is never
transaction question.
Transaction Atibes for MDB's
BMT bean setRollbackOnly
Transaction Mock Q!
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:36:16.