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?
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:
<configuration-name>INSERT after ejbPostCreate Container</configuration-name>
<container-configuration extends="Standard CMP 2.x EntityBean">
<container-name>INSERT after ejbPostCreate Container</container-name>
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)
You mean Standard vs Dynamic.
The main difference is that with standard mbeans the MBeanServer will use reflection to discover the exposed management interface that follows the XXXMBean pattern, and use also reflection to call the various attributes/operations - dynamic mbeans explicitly provide that metadata and also handle invocations without reflection.
In practice dynamic mbeans are rarely used because it's much more difficult to code them.
In JBoss there is a 3rd alternative, XMBean (i.e. jboss' implementation of ModelMBeans). They lets you wrap existing StandardMBeans or even simple POJOs, and be able to do things like:
specify metadata description for attributes/operations
produce notifications on attribute changes
persist attribute changes
attach interceptors to invocations
In other words combining the simplicity of StandardMBeans with the power of DynamicMBeans, but without the hassle.
I think the persistence of XMBeans is done by plugging the persistence interceptor into the interceptor stack. I have a question ragarding this. Is it possible to add the persistence interceptor to the stack of interceptors in the case of a regular dynamic MBean? And if yes could you please point out a few tips on how to do it?
Haven't tried that (i.e. to wrap a Dynamic MBean with an XMBean). It may be possible because all mbeans in jboss are proxied by an XMBean under the hood, whether you provide an xmbean descriptor or not.
I wonder in this case if you can avoid all the operation/attribute definitions.
A test is needed :)