Problem with N-M CMR on same table
tj99de Aug 6, 2004 9:54 AMHi,
I want to create a N:M CMR between records in the nuke_file table. Therefore I created an Entity Bean which contains the primary key of the nuke_file record an a Set which shall contain the primary keys of other records of the nuke_file table.
But when I try to add a relationship between two records I get this error message:
14:55:19,126 ERROR [Page] Cannot create link entries
javax.ejb.DuplicateKeyException: Entity with primary key 35 already exists
at org.jboss.ejb.plugins.cmp.jdbc.JDBCInsertPKCreateCommand.beforeInsert(JDBCInsertPKCreateCommand.java:90)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.execute(JDBCAbstractCreateCommand.java:137)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:554)
at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:208)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:269)
at org.jboss.ejb.EntityContainer.createLocalHome(EntityContainer.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:1043)
at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:88)
at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:197)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:214)
at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:88)
at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:89)
at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:61)
at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:28)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:88)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:267)
at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:98)
at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:92)
at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:120)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:93)
at org.jboss.ejb.EntityContainer.internalInvokeHome(EntityContainer.java:483)
at org.jboss.ejb.Container.invoke(Container.java:720)
at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invokeHome(BaseLocalProxyFactory.java:293)
at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java:110)
at $Proxy187.create(Unknown Source)
...
There is no record inserted into the relation table. For me it looks like it is tried to insert an additional record to the nuke_file table instead of the relation.
Here is my realtionship configuration in jbosscmp-jdbc.xml
<relationships>
<ejb-relation>
<ejb-relation-name>ParentLink</ejb-relation-name>
<relation-table-mapping>
<table-name>nuke_file_link</table-name>
<create-table>false</create-table>
<remove-table>false</remove-table>
</relation-table-mapping>
<ejb-relationship-role>
<ejb-relationship-role-name>Parent-has-Links</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>fileId</field-name>
<column-name>pn_id</column-name>
</key-field>
</key-fields>
<read-ahead>
<strategy>on-find</strategy>
</read-ahead>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>Link-has-Parents</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>fileId</field-name>
<column-name>pn_id</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
</ejb-relation>
</relationships>
And the ejb-jar.xml
<relationships >
<ejb-relation >
<ejb-relation-name>ParentLink</ejb-relation-name>
<ejb-relationship-role >
<ejb-relationship-role-name>Parent-has-Links</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source >
<ejb-name>ServiceFileEJB</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>links</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role >
<ejb-relationship-role-name>Link-has-Parents</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source >
<ejb-name>ServiceFileEJB</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
</ejb-relation>
</relationships>
Who may tell me what is wrong?
Thanks
tj99de