Howdy Ranchers!
I wanted to see if my CMT Transaction was reused in the following
EJB invocation.
You can easily achieve it using BMT and accessing UserTransaction. As the UserTransaction is not available for CMT, there is only one method which can give you some information about the transaction status - SessionContext#getRollbackOnly().
However I wanted to see if the following EJB was reusing the Tx, not just to see if it is maked for rollback, so I've made some tests with
TransactionSynchronizationRegistry.
It works fine and shows proper values, but my doubts are:
- Is accessing this object and getting the Tx status safe or it's possible that in some cases it would fail?
- I know it's intended to be used by system-level components, so I guess it's a little hacky to obtain it here, right?
- Is it
mandatory for the container to publish the resource at
java:comp/TransactionSynchronizationRegistry (the Javadoc talks only about
standard place).
- If it's safe to use, why do you think this object is not able to be injected using @Resource?
Thanks in advance,
Cheers!