setRollbackOnly is not working
linux__rulez Feb 1, 2006 6:52 PMIn the implemention of an MDB I stumble on something that I really did not expect, maybe someone can tell me where I go wrong?
I,
-declared Container Tx in ejb-jar.xml on my MDB
-inside the onMessage(Message) method I check some values which make me
-want to call setRollBackOnly()
Then I get an IllegalStateException from JBoss with this text:
00:26:11,653 ERROR [LogInterceptor] RuntimeException in method: public abstract void javax.jms.MessageListener.onMessage(javax.jms.Message): java.lang.IllegalStateException: setRollbackOnly should not be access for user managed Tx at org.jboss.ejb.MessageDrivenEnterpriseContext$MessageDrivenContextImpl.setRollbackOnly(MessageDrivenEnterpriseContext.java:202) at bank.ejb.TransactionManagerMBean.onMessage(TransactionManagerMBean.java:123) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) <SNAP>
setRollbackOnly should not be access for user managed Tx
It comes from this piece of sourcecode:
<<<<<<<<<<<<<SNAP>>>>>>>>>>>>>> /** * If transaction type is not Container or there is no transaction * then throw an exception. * * @throws IllegalStateException If transaction type is not Container, * or no transaction. */ public void setRollbackOnly() { if (isUserManagedTx()) throw new IllegalStateException("setRollbackOnly should not be access for user managed Tx"); AllowedOperationsAssociation.assertAllowedIn("getRollbackOnly", IN_BUSINESS_METHOD | IN_EJB_TIMEOUT); if (!isTxRequired()) { throw new IllegalStateException ("setRollbackOnly must only be called in the context of a transaction (EJB 2.0 - 15.5.1)"); } super.setRollbackOnly(); } /** Helper to check if the tx type is TX_REQUIRED. */ private boolean isTxRequired() { MessageDrivenMetaData md = (MessageDrivenMetaData)con.getBeanMetaData(); return md.getMethodTransactionType() == MetaData.TX_REQUIRED; } }
This is my ejb-jar.xml
<<<<<<<<<<<<<<SNAP>>>>>>>>>>>> <message-driven> <ejb-name>TransactionManagerMBean</ejb-name> <ejb-class>bank.ejb.TransactionManagerMBean</ejb-class> <transaction-type>Bean</transaction-type> <message-driven-destination> <destination-type>javax.jms.Queue</destination-type> </message-driven-destination> <ejb-local-ref> <ejb-ref-name>ejb/AccountBean</ejb-ref-name> <ejb-ref-type>Entity</ejb-ref-type> <local-home>bank.ejb.AccountLHome</local-home> <local>bank.ejb.Account</local> <ejb-link>AccountBean</ejb-link> </ejb-local-ref> <ejb-local-ref> <ejb-ref-name>ejb/TransactionBean</ejb-ref-name> <ejb-ref-type>Entity</ejb-ref-type> <local-home>bank.ejb.TransactionLHome</local-home> <local>bank.ejb.Transaction</local> <ejb-link>TransactionBean</ejb-link> </ejb-local-ref> </message-driven> </enterprise-beans> <assembly-descriptor> <container-transaction> <method> <ejb-name>TransactionManagerMBean</ejb-name> <method-name>*</method-name> </method> <trans-attribute>Required</trans-attribute> </container-transaction> </assembly-descriptor>
I know I must be wrong, but where?
Thanks for any hints in advance,
Johannes