Java Reference
In-Depth Information
getRollbackOnly : Use this method to test whether the current transaction has
been marked for rollback.
If you use bean-managed transactions, the delivery of a message to the onMessage
method takes place outside the distributed transaction context. The transaction begins
when you call the UserTransaction.begin method within the onMessage meth-
od, and it ends when you call UserTransaction.commit or UserTransac-
tion.rollback . Any call to the Connection.createSession method must
take place within the transaction. If you call UserTransaction.rollback , the mes-
sage is not redelivered, whereas calling setRollbackOnly for container-managed
transactions does cause a message to be redelivered.
Neither the JMS API specification nor the Enterprise JavaBeans specification (available
from http://jcp.org/en/jsr/detail?id=318 ) specifies how to handle calls
to JMS API methods outside transaction boundaries. The Enterprise JavaBeans specific-
ation does state that the EJB container is responsible for acknowledging a message that
is successfully processed by the onMessage method of a message-driven bean that uses
bean-managed transactions. Using bean-managed transactions allows you to process the
message by using more than one transaction or to have some parts of the message process-
ing take place outside a transaction context. In most cases, however, container-managed
transactions provide greater reliability and are therefore preferable.
When you create a session in an enterprise bean, the container ignores the arguments you
specify, because it manages all transactional properties for enterprise beans. It is still a
good idea to specify arguments of true and 0 to the createSession method to make
this situation clear:
session = connection.createSession(true, 0);
When you use container-managed transactions, you normally use the Required transac-
tion attribute (the default) for your enterprise bean's business methods.
You do not specify a message acknowledgment mode when you create a message-driven
bean that uses container-managed transactions. The container acknowledges the message
automatically when it commits the transaction.
If a message-driven bean uses bean-managed transactions, the message receipt cannot be
part of the bean-managed transaction, so the container acknowledges the message outside
the transaction.
If the onMessage method throws a RuntimeException , the container does not ac-
knowledge processing the message. In that case, the JMS provider will redeliver the un-
acknowledged message in the future.
Search WWH ::




Custom Search