You are developing a message-listener method of an EJB 3.0 message driven bean. You need to make sure that the message receipt is immediately rolled back in case the message listener method is aborted with a runtime exception
Select the best design approach.
A. Use container managed transaction with transaction attribute REQUIRED.
B.Use container managed transaction with transaction attribute NOT_SUPPORTED
c. use bean managed transactions and the JMS API for message acknowledgement
d. Use bean managed transaction and write a try-catch-finally block that calls UserTransaction.rollback in case of a RuntimeException
Given answer :A
Based on the requirements, CMT with REQUIRED transaction attribute is the correct answer. REQUIRED transaction attribute run a method within a transaction and rollback if there is any runtime exception.
I think if the runtime exception is an application exception, using CMT with REQUIRED may not rollback the transaction if the application exception specify rollback=false.
I think D is the best approach because it explicitly specifies that the transaction needs to be rollback when the exception occurs.
Just the other day, I was thinking ... about this tiny ad: