This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
What will happen in a stateless or MDB with BMT demarcation if we throw an Application Exception after the transaction has been started but not commited ? According to specs, the app-exception will be re-thrown. But, according to specs too, these ejbs need to commit or rollback the transaction before the method ends.
javax.ejb.EJBException: Application error: BMT stateless bean MySLSFBean should complete transactions before returning (ejb1.1 spec, 11.6.1); nested exception is: bmtappexception.MyAppException Caused by: bmtappexception.MyAppException at bmtappexception.MySLSFBean.test(MySLSFBean.java:21)
So, even if you throw an application exception, you need to commit/rollback your transaction (probably in a finally clause).
Hope it helps,
SCJP5 | SCBCD5 | SCEA5 Part 1
Joined: Apr 03, 2008
Thinking about it the two statements i've mentioned from the specs are really not contradictory. The exception will be rethrown and the method won't have commited or rollbacked, so a sytem-exception is thrown, the transaction rollbacked and the instance discarded .