JBoss 3.0RC3 CMP 2.0: java.lang.IllegalStateException: remov
obergner May 23, 2002 1:16 PMHello,
this is my first attempt at EJB, trying to follow Richard Monson-Haefel's book. I am stuck with the One-to-One Bidirectional Relationship (CMR) involving a customer bean and a credit card bean.The underlying database is PostgreSQL.
In my table layout, I have a column "credit_card_id" pointing from the customer table to the credit card table and a column "customer_id" pointing from the credit card table to the customer table.
Deployment went just fine (after a while;)), so I wrote a simple test client that creates a customer bean and calls setCreditCardDO(creditCardDO) on the customer.
The result looks as follows:
18:24:45,676 ERROR [LogInterceptor] TransactionRolledbackException, causedBy:
java.lang.IllegalStateException: removing bean lock and it has tx set!
at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.removeRef(QueuedPessimisticEJBLock.java:469)
at org.jboss.ejb.BeanLockManager.removeLockRef(BeanLockManager.java:78)
at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:124)
at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:69)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:96)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:167)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:61)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:129)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)
at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke(BaseLocalContainerInvoker.java:296)
at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)
at $Proxy39.getPrimaryKey(Unknown Source)
at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.setInstanceValue(JDBCCMRFieldBridge.java:625)
at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.setValue(JDBCCMRFieldBridge.java:563)
at org.jboss.ejb.plugins.cmp.bridge.EntityBridgeInvocationHandler.invoke(EntityBridgeInvocationHandler.java:125)
at org.jboss.proxy.compiler.Runtime.invoke(Runtime.java:59)
at com.titan.customer.CustomerBean$Proxy.setCreditCard()
at com.titan.customer.CustomerBean.setCreditCardDO(CustomerBean.java:248)
at java.lang.reflect.Method.invoke(Native Method)
at org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke(EntityContainer.java:1197)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke(JDBCRelationInterceptor.java:190)
at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:340)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:147)
at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:193)
at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:107)
at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:69)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:96)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:167)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:61)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:129)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)
at org.jboss.ejb.Container.invoke(Container.java:705)
at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1055)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:364)
at java.lang.reflect.Method.invoke(Native Method)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:241)
at sun.rmi.transport.Transport$1.run(Transport.java:152)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:148)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:465)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:706)
at java.lang.Thread.run(Thread.java:484)
The PostgreSQL logfile says:
DEBUG: query: SELECT COUNT(*) FROM customer WHERE ID=2
DEBUG: query: INSERT INTO customer (ID, last_name, first_name, credit_card_id) VALUES (2, null, null, null)
DEBUG: query: commit;begin;
DEBUG: ProcessUtility: commit;begin;
DEBUG: ProcessUtility: commit;begin;
DEBUG: query: SELECT last_name, first_name, credit_card_id FROM customer WHERE (ID=2)
DEBUG: query: SELECT COUNT(*) FROM credit_card WHERE ID=null
DEBUG: query: INSERT INTO credit_card (ID, exp_date, number, name, organization, customer_id) VALUES (null, '1010 Colorado', 'Austin', 'TX', '78701', null)
DEBUG: query: SELECT $1 IS NULL
DEBUG: query: SELECT -1
DEBUG: query: rollback; begin;
DEBUG: ProcessUtility: rollback; begin;
DEBUG: ProcessUtility: rollback; begin;
This is the relevant part of my ejb-jar.xml:
(CustomerEJB)
<ejb-name>CustomerEJB</ejb-name>
com.titan.customer.CustomerHomeRemote
com.titan.customer.CustomerRemote
<local-home>com.titan.customer.CustomerHomeLocal</local-home>
com.titan.customer.CustomerLocal
<ejb-class>com.titan.customer.CustomerBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
False
<cmp-version>2.x</cmp-version>
<abstract-schema-name>Customer</abstract-schema-name>
<cmp-field>
<field-name>ID</field-name>
</cmp-field>
<cmp-field>
<field-name>lastName</field-name>
</cmp-field>
<cmp-field>
<field-name>firstName</field-name>
</cmp-field>
<primkey-field>ID</primkey-field>
<ejb-local-ref>
<ejb-ref-name>ejb/CreditCardHomeLocal</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local-home>com.titan.creditcard.CreditCardHomeLocal</local-home>
com.titan.creditcard.CreditCardLocal
<ejb-link>CreditCardEJB</ejb-link>
</ejb-local-ref>
<security-identity><use-caller-identity/></security-identity>
(CreditCardEJB)
<ejb-name>CreditCardEJB</ejb-name>
<local-home>com.titan.creditcard.CreditCardHomeLocal</local-home>
com.titan.creditcard.CreditCardLocal
<ejb-class>com.titan.creditcard.CreditCardBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
False
<cmp-version>2.x</cmp-version>
<abstract-schema-name>CreditCard</abstract-schema-name>
<cmp-field>
<field-name>ID</field-name>
</cmp-field>
<cmp-field>
<field-name>expirationDate</field-name>
</cmp-field>
<cmp-field>
<field-name>number</field-name>
</cmp-field>
<cmp-field>
<field-name>nameOnCard</field-name>
</cmp-field>
<cmp-field>
<field-name>creditOrganization</field-name>
</cmp-field>
<primkey-field>ID</primkey-field>
<security-identity><use-caller-identity/></security-identity>
(Relationships)
<ejb-relation>
<ejb-relation-name>Customer-CreditCard</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>Customer-owns-a-CreditCard</ejb-relationship-role-name>
One
<relationship-role-source>
<ejb-name>CustomerEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>creditCard</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>CreditCard-is-owned-by-Customer</ejb-relationship-role-name>
One
<relationship-role-source>
<ejb-name>CreditCardEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>customer</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
The corresponding parts from jbosscmp-jdbc.xml:
(CustomerEJB)
<ejb-name>CustomerEJB</ejb-name>
<table-name>customer</table-name>
<cmp-field>
<field-name>ID</field-name>
<column-name>ID</column-name>
</cmp-field>
<cmp-field>
<field-name>lastName</field-name>
<column-name>last_name</column-name>
</cmp-field>
<cmp-field>
<field-name>firstName</field-name>
<column-name>first_name</column-name>
</cmp-field>
(CreditCardEJB)
<ejb-name>CreditCardEJB</ejb-name>
<table-name>credit_card</table-name>
<cmp-field>
<field-name>ID</field-name>
<column-name>ID</column-name>
</cmp-field>
<cmp-field>
<field-name>expirationDate</field-name>
<column-name>exp_date</column-name>
</cmp-field>
<cmp-field>
<field-name>number</field-name>
<column-name>number</column-name>
</cmp-field>
<cmp-field>
<field-name>nameOnCard</field-name>
<column-name>name</column-name>
</cmp-field>
<cmp-field>
<field-name>creditOrganization</field-name>
<column-name>organization</column-name>
</cmp-field>
(Relationships)
<ejb-relation>
<ejb-relation-name>Customer-CreditCard</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>Customer-owns-a-CreditCard</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>ID</field-name>
<column-name>customer_id</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>CreditCard-is-owned-by-Customer</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>ID</field-name>
<column-name>credit_card_id</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
</ejb-relation>
Sorry for the long read, but I have been stuck with this problem for three days (and nights), and I wanted to provide as much information as possible.
Since the exception implies a transactional problem I should add that the transactional attribute of every method involved is set to "Required". Yet somehow I doubt this is a problem with the transactional context.
I had no (severe) problems establishing the One-to-One Unidirectional Relationship between a customer and his address, using a link table. Does this imply that I am not a complete moron?
Any help would be greatly appreciated.
Thanks,
Olaf