CMR relation on NOT NULL foreign keys
sha Dec 15, 2003 11:41 AMHi everybody!
Does anybody know how to set up a one to one cmr relationship build upon a foreign key constraint that owns a NOT NULL constraint?
Setting:
I implemented two CMP beans EntityA and EntityB corresponding to tables A and B. Table A refers to table B's primary key via a foreign key constraint. This foreign key is further restricted by a NOT NULL constraint.
Since the CMR relation on the foreign key has to be set in ejbPostCreate() but the database insert takes place between the ejbCreate() and ejbPostCreste() methods, it fails due to a voilated NOT NULL constraint.
I tried to defer the insert using a custom container configuration merged into jboss.xml:
...
<ejb-name>EntityA</ejb-name>
<jndi-name>EntityAHome</jndi-name>
<local-jndi-name>EntityArLocalHome</local-jndi-name>
<configuration-name>INSERT after ejbPostCreate Container</configuration-name>
<ejb-ref>
<ejb-ref-name>ejb/EntityB</ejb-ref-name>
<jndi-name>EntityBHome</jndi-name>
</ejb-ref>
<method-attributes>
</method-attributes>
...
<container-configurations>
<container-configuration extends="Standard CMP 2.x EntityBean">
<container-name>INSERT after ejbPostCreate Container</container-name>
<insert-after-ejb-post-create>true</insert-after-ejb-post-create>
</container-configuration>
</container-configurations>
Unfortunately this does not work and and yields to the the following error
[java] Data contains multiple values, but this cmr field is single valued; nested exception is:
[java] javax.ejb.EJBException: Data contains multiple values, but this cmr field is single valued; - nested throwable: (javax.ejb.EJBException: Data contains multiple values, but this cmr field is single valued)
[java] at org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.java:262)
[java] at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
[java] at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
[java] at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:331)
[java] at org.jboss.ejb.Container.invoke(Container.java:700)
Thanks
Stefan