Using Transactions with Message-Driven BeansAs with session beans, message-driven beans can use either bean-managed transactions or container-managed transactions. Because a client has no way to call the message-driven bean directly, the client can't propagate its transaction context to the message-driven bean. The container will always call the onMessage method with a transaction context that is specified in the bean's deployment descriptor. Therefore, a message-driven bean that is using container-managed transaction should specify either the Required or NotSupported transaction attribute in the ejb-jar.xml file. This is because if the message-driven bean needs a transaction, the container will have to create one before calling the onMessage method, because there's no chance to propagate a transaction from the client. If the message-driven bean doesn't need a transaction, you should specify the NotSupported transaction attribute. For more information on transactions, see Chapter 12, "Transactions." |