Bugs item #541092, was opened at 2002-04-08 11:49
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=376685&aid=541092&group_id=22866
Category: JBossCMP
Group: v3.0 Rabbit Hole
>Status: Closed
>Resolution: Out of Date
Priority: 5
Submitted By: Peter Luttrell (objec)
Assigned to: Dain Sundstrom (dsundstrom)
Summary: Entity Bean Relationships Not Working
Initial Comment:
I have created 2 entity beans that are related in a
many-to-many unidirectional relationship. For the
point of the bug report the example will be User-to-
roles.
I have a tester class that create a new user, set some
other fields and then calls the addRoleByName method a
few times. If I deploy the beans, and then run the
test class, jboss properly creates the beans.
However once I restart jboss and run the exact same
tester class (different primary keys), Jboss blows up.
It also does so on all subsequent runs. Here�s the
exception:
11:24:36,560 ERROR [LogInterceptor]
TransactionRolledbackException, causedBy:
java.lang.IllegalStateException: A CMR field cannot be
set or added to a relationship in ejbCreate;
this should be done in the ejbPostCreate method
instead [EJB 2.0 Spec. 10.5.2].
at
org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridg
e.addRelation(JDBCCMRFieldBridge.j
ava:749)
at
org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.
invoke(JDBCRelationInterceptor.jav
a:146)
at
org.jboss.ejb.plugins.EntitySynchronizationInterceptor.
invoke(EntitySynchronizationInterc
eptor.java:296)
at
org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke
(EntityInstanceInterceptor.java:189
)
at
org.jboss.ejb.plugins.EntityLockInterceptor.invoke
(EntityLockInterceptor.java:108)
at
org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext
(AbstractTxInterceptor.java:96)
at
org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransacti
ons(TxInterceptorCMT.java:167)
at
org.jboss.ejb.plugins.TxInterceptorCMT.invoke
(TxInterceptorCMT.java:61)
at
org.jboss.ejb.plugins.SecurityInterceptor.invoke
(SecurityInterceptor.java:127)
at org.jboss.ejb.plugins.LogInterceptor.invoke
(LogInterceptor.java:166)
at org.jboss.ejb.EntityContainer.invoke
(EntityContainer.java:475)
at
org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridg
e.invokeAddRelation(JDBCCMRFieldBr
idge.java:682)
at
org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridg
e.createRelationLinks(JDBCCMRField
Bridge.java:609)
at
org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.add
(RelationSet.java:89)
at
com.starkinvestments.security.users.UserBean.addRole
(UserBean.java:77)
at java.lang.reflect.Method.invoke(Native
Method)
at
org.jboss.ejb.EntityContainer$ContainerInterceptor.invo
ke(EntityContainer.java:1127)
at
org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.
invoke(JDBCRelationInterceptor.jav
a:184)
at
org.jboss.ejb.plugins.EntitySynchronizationInterceptor.
invoke(EntitySynchronizationInterc
eptor.java:296)
at
org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke
(EntityInstanceInterceptor.java:189
)
at
org.jboss.ejb.plugins.EntityLockInterceptor.invoke
(EntityLockInterceptor.java:108)
at
org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext
(AbstractTxInterceptor.java:96)
at
org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransacti
ons(TxInterceptorCMT.java:167)
at
org.jboss.ejb.plugins.TxInterceptorCMT.invoke
(TxInterceptorCMT.java:61)
at
org.jboss.ejb.plugins.SecurityInterceptor.invoke
(SecurityInterceptor.java:127)
at org.jboss.ejb.plugins.LogInterceptor.invoke
(LogInterceptor.java:166)
at org.jboss.ejb.EntityContainer.invoke
(EntityContainer.java:475)
at org.jboss.ejb.Container.invoke
(Container.java:630)
at org.jboss.ejb.EntityContainer.invoke
(EntityContainer.java:995)
at
com.sun.management.jmx.MBeanServerImpl.invoke
(MBeanServerImpl.java:1555)
at
com.sun.management.jmx.MBeanServerImpl.invoke
(MBeanServerImpl.java:1523)
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.ru
n(TCPTransport.java:706)
at java.lang.Thread.run(Thread.java:484)
11:24:36,575 ERROR [JRMPInvoker] operation failed
java.rmi.ServerException: Error in addRelation
Embedded Exception
A CMR field cannot be set or added to a relationship
in ejbCreate; this should be done in the ejbPos
tCreate method instead [EJB 2.0 Spec. 10.5.2].; nested
exception is:
java.lang.IllegalStateException: A CMR field
cannot be set or added to a relationship in ejb
Create; this should be done in the ejbPostCreate
method instead [EJB 2.0 Spec. 10.5.2].; nested exce
ption is:
javax.ejb.EJBException: Error in addRelation
Embedded Exception
A CMR field cannot be set or added to a relationship
in ejbCreate; this should be done in the ejbPos
tCreate method instead [EJB 2.0 Spec. 10.5.2].; nested
exception is:
java.lang.IllegalStateException: A CMR field
cannot be set or added to a relationship in ejb
Create; this should be done in the ejbPostCreate
method instead [EJB 2.0 Spec. 10.5.2].
javax.ejb.EJBException: Error in addRelation
Embedded Exception
A CMR field cannot be set or added to a relationship
in ejbCreate; this should be done in the ejbPos
tCreate method instead [EJB 2.0 Spec. 10.5.2].; nested
exception is:
java.lang.IllegalStateException: A CMR field
cannot be set or added to a relationship in ejb
Create; this should be done in the ejbPostCreate
method instead [EJB 2.0 Spec. 10.5.2].
at
org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridg
e.invokeAddRelation(JDBCCMRFieldBr
idge.java:692)
at
org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridg
e.createRelationLinks(JDBCCMRField
Bridge.java:609)
at
org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.add
(RelationSet.java:89)
at
com.starkinvestments.security.users.UserBean.addRole
(UserBean.java:77)
at java.lang.reflect.Method.invoke(Native
Method)
at
org.jboss.ejb.EntityContainer$ContainerInterceptor.invo
ke(EntityContainer.java:1127)
at
org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.
invoke(JDBCRelationInterceptor.jav
a:184)
at
org.jboss.ejb.plugins.EntitySynchronizationInterceptor.
invoke(EntitySynchronizationInterc
eptor.java:296)
at
org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke
(EntityInstanceInterceptor.java:189
)
at
org.jboss.ejb.plugins.EntityLockInterceptor.invoke
(EntityLockInterceptor.java:108)
at
org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext
(AbstractTxInterceptor.java:96)
at
org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransacti
ons(TxInterceptorCMT.java:167)
at
org.jboss.ejb.plugins.TxInterceptorCMT.invoke
(TxInterceptorCMT.java:61)
at
org.jboss.ejb.plugins.SecurityInterceptor.invoke
(SecurityInterceptor.java:127)
at org.jboss.ejb.plugins.LogInterceptor.invoke
(LogInterceptor.java:166)
at org.jboss.ejb.EntityContainer.invoke
(EntityContainer.java:475)
at org.jboss.ejb.Container.invoke
(Container.java:630)
at org.jboss.ejb.EntityContainer.invoke
(EntityContainer.java:995)
at
com.sun.management.jmx.MBeanServerImpl.invoke
(MBeanServerImpl.java:1555)
at
com.sun.management.jmx.MBeanServerImpl.invoke
(MBeanServerImpl.java:1523)
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.ru
n(TCPTransport.java:706)
at java.lang.Thread.run(Thread.java:484)
javax.transaction.TransactionRolledbackException: A
CMR field cannot be set or added to a relationsh
ip in ejbCreate; this should be done in the
ejbPostCreate method instead [EJB 2.0 Spec. 10.5.2].;
ne
sted exception is:
java.lang.IllegalStateException: A CMR field
cannot be set or added to a relationship in ejb
Create; this should be done in the ejbPostCreate
method instead [EJB 2.0 Spec. 10.5.2].
java.lang.IllegalStateException: A CMR field cannot be
set or added to a relationship in ejbCreate;
this should be done in the ejbPostCreate method
instead [EJB 2.0 Spec. 10.5.2].
at
org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridg
e.addRelation(JDBCCMRFieldBridge.j
ava:749)
at
org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.
invoke(JDBCRelationInterceptor.jav
a:146)
at
org.jboss.ejb.plugins.EntitySynchronizationInterceptor.
invoke(EntitySynchronizationInterc
eptor.java:296)
at
org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke
(EntityInstanceInterceptor.java:189
)
at
org.jboss.ejb.plugins.EntityLockInterceptor.invoke
(EntityLockInterceptor.java:108)
at
org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext
(AbstractTxInterceptor.java:96)
at
org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransacti
ons(TxInterceptorCMT.java:167)
at
org.jboss.ejb.plugins.TxInterceptorCMT.invoke
(TxInterceptorCMT.java:61)
at
org.jboss.ejb.plugins.SecurityInterceptor.invoke
(SecurityInterceptor.java:127)
at org.jboss.ejb.plugins.LogInterceptor.invoke
(LogInterceptor.java:166)
at org.jboss.ejb.EntityContainer.invoke
(EntityContainer.java:475)
at
org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridg
e.invokeAddRelation(JDBCCMRFieldBr
idge.java:682)
at
org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridg
e.createRelationLinks(JDBCCMRField
Bridge.java:609)
at
org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.add
(RelationSet.java:89)
at
com.starkinvestments.security.users.UserBean.addRole
(UserBean.java:77)
at java.lang.reflect.Method.invoke(Native
Method)
at
org.jboss.ejb.EntityContainer$ContainerInterceptor.invo
ke(EntityContainer.java:1127)
at
org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.
invoke(JDBCRelationInterceptor.jav
a:184)
at
org.jboss.ejb.plugins.EntitySynchronizationInterceptor.
invoke(EntitySynchronizationInterc
eptor.java:296)
at
org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke
(EntityInstanceInterceptor.java:189
)
at
org.jboss.ejb.plugins.EntityLockInterceptor.invoke
(EntityLockInterceptor.java:108)
at
org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext
(AbstractTxInterceptor.java:96)
at
org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransacti
ons(TxInterceptorCMT.java:167)
at
org.jboss.ejb.plugins.TxInterceptorCMT.invoke
(TxInterceptorCMT.java:61)
at
org.jboss.ejb.plugins.SecurityInterceptor.invoke
(SecurityInterceptor.java:127)
at org.jboss.ejb.plugins.LogInterceptor.invoke
(LogInterceptor.java:166)
at org.jboss.ejb.EntityContainer.invoke
(EntityContainer.java:475)
at org.jboss.ejb.Container.invoke
(Container.java:630)
at org.jboss.ejb.EntityContainer.invoke
(EntityContainer.java:995)
at
com.sun.management.jmx.MBeanServerImpl.invoke
(MBeanServerImpl.java:1555)
at
com.sun.management.jmx.MBeanServerImpl.invoke
(MBeanServerImpl.java:1523)
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.ru
n(TCPTransport.java:706)
at java.lang.Thread.run(Thread.java:484)
The method of my code that it�s executing is:
addRoleByName(String roleName){
get the home interface for the role bean
try{
roleLocalInterface = findByPrimaryKey(roleName)
} catch (ObjectNotFoundException)
roleLocalInterface = create(roleName)
}
Set roles = this.getRoles(); //cmp field
roles.add(roleLocalInterface);
}
It blows up on roles.add(role) for existing roles (I
haven�t really tested new roles in this scenario).
It is my understanding that at this point, since it
has a reference to the role via the findByPrimaryKey
method, it should not be calling any ejbCreate method,
which looks like what is happening in the stack trace,
which leads me to believe that somehow jboss is down
some vogue execution path.
If this is not the case, perhaps there is an issue
with the code that Jboss generates, because I�m not
calling setRelation as indicated in the stack trace.
For the user amd role bean the ejbCreate and
ejbPostCreate methods are exactly the same. Here�s the
code (note that the name is the primarykey for both):
public String ejbCreate(String name){
setName(name);
return null;
}
public void ejbPostCreate(String name){
}
Here�s a snippet of the deployment descriptor that
might be relevant (modified for this example):
<relationships>
<ejb-relation>
<ejb-relation-name>User-Roles</ejb-
relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>User-has-
multiple-Roles</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source>
<ejb-name>Users</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>roles</cmr-field-
name>
<cmr-field-type>java.util.Set</cmr-
field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>Role-
Belongs-To-User</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source>
<ejb-name>Roles</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
</ejb-relation>
</relationships>
This problem was likely not caught by the unit tests
because it is exposed by restarting jboss.
I would like to supply sample code, but my company
will not allow it. If you can't reproduce the problem,
please email me and I'll put something together.
thanks.
----------------------------------------------------------------------
>Comment By: Dain Sundstrom (dsundstrom)
Date: 2002-04-12 16:41
Message:
Logged In: YES
user_id=251431
This has been fixed in CVS.
----------------------------------------------------------------------
Comment By: Peter Luttrell (objec)
Date: 2002-04-09 22:53
Message:
Logged In: YES
user_id=472835
i am using beta1
----------------------------------------------------------------------
Comment By: Dain Sundstrom (dsundstrom)
Date: 2002-04-09 11:13
Message:
Logged In: YES
user_id=251431
Are you using beta 1 or cvs source? I think I fixed
already fixed this in the cvs source.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=376685&aid=541092&group_id=22866
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development