This content has been marked as final.
Show 1 reply
-
1. Re: Accessing <transaction-type> configration of ejb-jar.xml in EJB class
sjunejo Dec 30, 2013 3:14 PM (in response to sjunejo)I found out that we do not have any way of directly accessing this information.
However, you can get at the information indirectly by relying on the fact that EJBContext.getUserTransaction throws an exception for CMT:
@Resource EJBContext ejbContext;
private boolean isBeanManagedTransaction() {
try {
ejbContext.getUserTransaction();
return true;
}
catch (IllegalStateException e)
{return false;
}
}
Note, the getUserTransaction method cannot be called from all container callbacks (see the table of allowed operations in the EJB spec), but fortunately, getUserTransaction can be called from ejbCreate/PostConstruct, so this method works for me.