5 Replies Latest reply on Dec 20, 2001 3:24 AM by Carole.D

    One to Many relationship problem

    Carole.D Newbie

      Hi All,
      I'm trying to implement a One to Many relationship between two CMP 2.0 entities the devise bean and gprd bean ,I'm using JBoss3.0.0 alpha version .
      The jar file containing the beans is deployed correctly but when I try to access the CMR field deviseCMR using gprd.getDeviseCMR() I got the following
      error:

      /***************** error on the JBoss console*****************************************/
      java.rmi.ServerException: null
      Embedded Exception
      null; nested exception is:
      javax.ejb.EJBException: null
      Embedded Exception
      null
      javax.ejb.EJBException: null
      Embedded Exception
      null
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.getValue(JDBCCMRFieldBridge.java:404)
      at org.jboss.ejb.plugins.cmp.bridge.EntityBridgeInvocationHandler.invoke(EntityBridgeInvocationHandler.java:111)
      at org.jboss.proxy.ProxyCompiler$Runtime.invoke(ProxyCompiler.java:89)
      at demo.ejbent.gprd.GprdBean$Proxy.getDeviseCMR(Unknown Source)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke(EntityContainer.java:1002)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCReadAheadInterceptor.invoke(JDBCReadAheadInterceptor.java:100)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke(JDBCRelationInterceptor.java:134)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:308)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:201)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:132)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:98)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:156)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:65)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:131)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:447)
      at org.jboss.ejb.Container.invoke(Container.java:528)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1555)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
      at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPContainerInvoker.java:411)
      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:142)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:139)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:443)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:643)
      at java.lang.Thread.run(Thread.java:484)
      java.lang.NullPointerException
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.getEntityEJBLocalObject(BaseLocalContainerInvoker.java:226)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.getValue(JDBCCMRFieldBridge.java:399)
      at org.jboss.ejb.plugins.cmp.bridge.EntityBridgeInvocationHandler.invoke(EntityBridgeInvocationHandler.java:111)
      at org.jboss.proxy.ProxyCompiler$Runtime.invoke(ProxyCompiler.java:89)
      at demo.ejbent.gprd.GprdBean$Proxy.getDeviseCMR(Unknown Source)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke(EntityContainer.java:1002)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCReadAheadInterceptor.invoke(JDBCReadAheadInterceptor.java:100)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke(JDBCRelationInterceptor.java:134)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:308)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:201)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:132)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:98)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:156)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:65)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:131)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:447)
      at org.jboss.ejb.Container.invoke(Container.java:528)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1555)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
      at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPContainerInvoker.java:411)
      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:142)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:139)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:443)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:643)
      at java.lang.Thread.run(Thread.java:484)

      /************************************************************************/
      Here is the implementation :


      the ejb-jar .xml is :
      /*******************************************************************/
      <ejb-jar>
      <enterprise-beans>


      The Demo EJB
      <ejb-name>DeviseEJB</ejb-name>
      demo.ejbent.devise.DeviseHome
      demo.ejbent.devise.Devise
      <ejb-class>demo.ejbent.devise.DeviseBean</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>DeviseBean</abstract-schema-name>
      <cmp-field>
      <field-name>devise_Id</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>devi_Lib</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>devi_Taux</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>devi_Abreviation</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>devi_Symbole</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>devi_DateModif</field-name>
      </cmp-field>
      <primkey-field>devise_Id</primkey-field>


      Find with id greater
      <query-method>
      <method-name>findByDeviTaux</method-name>
      <method-params>
      <method-param>java.lang.Double</method-param>
      </method-params>
      </query-method>
      <ejb-ql>
      <![CDATA[WHERE devi_Taux = ?1]]>
      </ejb-ql>




      The Gprd EJB
      <ejb-name>GprdEJB</ejb-name>
      demo.ejbent.gprd.GprdHome
      demo.ejbent.gprd.Gprd
      <ejb-class>demo.ejbent.gprd.GprdBean</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>GprdBean</abstract-schema-name>
      <cmp-field><field-name>gprdId</field-name></cmp-field>
      <cmp-field><field-name>raysId</field-name></cmp-field>
      <cmp-field><field-name>fourId</field-name></cmp-field>
      <cmp-field><field-name>gprdLib</field-name></cmp-field>
      <cmp-field><field-name>devId</field-name></cmp-field>
      <cmp-field><field-name>respId</field-name></cmp-field>
      <primkey-field>gprdId</primkey-field>


      </enterprise-beans>



      <ejb-relation>
      <ejb-relation-name>DeviseGprd</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Devise-has-gprds</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>DeviseEJB</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>gprds</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Gprd-belongto-Devise</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>GprdEJB</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>deviseCMR</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      </ejb-relation>


      <assembly-descriptor>
      <container-transaction>

      <ejb-name>DeviseEJB</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>

      <ejb-name>GprdEJB</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>
      </ejb-jar>
      /******************************************************************/
      the jbosscmp-jdbc.xml is the following
      /******************************************************************/
      <?xml version="1.0" encoding="UTF-8"?>
      <jbosscmp-jdbc>

      java:/DefaultDS
      false
      <create-table>true</create-table>
      <remove-table>true</remove-table>
      <tuned-updates>true</tuned-updates>
      <read-only>false</read-only>
      <time-out>300</time-out>
      <select-for-update>false</select-for-update>
      <pk-constraint>true</pk-constraint>
      <relation-mapping-style>foreign-key</relation-mapping-style>


      <enterprise-beans>

      <ejb-name>DeviseEJB</ejb-name>
      <table-name>Devise</table-name>
      <create-table>false</create-table>
      <cmp-field>
      <field-name>devise_Id</field-name>
      <column-name>devi_Id</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>devi_Lib</field-name>
      <column-name>devi_Lib</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>devi_Taux</field-name>
      <column-name>devi_Taux</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>devi_Abreviation</field-name>
      <column-name>devi_Abreviation</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>devi_Symbole</field-name>
      <column-name>devi_Symbole</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>devi_DateModif</field-name>
      <column-name>devi_DateModif</column-name>
      </cmp-field>

      Find all orders with the specified status
      <query-method>
      <method-name>findByDeviTaux</method-name>
      <method-params>
      <method-param>java.lang.Double</method-param>
      </method-params>
      </query-method>
      <declared-sql>
      devi_Taux={0}
      devi_Id ASC
      </declared-sql>




      <ejb-name>GprdEJB</ejb-name>
      <table-name>Gprd</table-name>
      <create-table>false</create-table>
      <cmp-field>
      <field-name>gprdId</field-name>
      <column-name>gprd_Id</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>raysId</field-name>
      <column-name>rays_Id</column-name>

      </cmp-field>
      <cmp-field>
      <field-name>fourId</field-name>
      <column-name>four_Id</column-name>

      </cmp-field>
      <cmp-field>
      <field-name>gprdLib</field-name>
      <column-name>gprd_Lib</column-name>

      </cmp-field>
      <cmp-field>
      <field-name>devId</field-name>
      <column-name>devi_Id</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>respId</field-name>
      <column-name>resp_Id</column-name>
      </cmp-field>


      </enterprise-beans>

      <ejb-relation>
      <ejb-relation-name>DeviseGprd</ejb-relation-name>
      <foreign-key-mapping>

      <ejb-relationship-role>
      <ejb-relationship-role-name>Devise-has-gprds</ejb-relationship-role-name>
      <foreign-key-fields/>
      </ejb-relationship-role>

      <ejb-relationship-role>
      <ejb-relationship-role-name>Gprd-belongto-Devise</ejb-relationship-role-name>
      <foreign-key-fields>
      <foreign-key-field>
      <field-name>devise_Id</field-name>
      <column-name>devi_Id</column-name>
      </foreign-key-field>

      </foreign-key-fields>
      </ejb-relationship-role>

      </foreign-key-mapping>
      </ejb-relation>


      </jbosscmp-jdbc>

      /***********************************************************************/
      here is the remote interface of the Gprd bean :

      /***********************************************************************/
      package demo.ejbent.gprd;

      import java.rmi.*;
      import javax.ejb.*;
      import java.math.*;
      import java.sql.*;
      import java.util.*;
      import demo.ejbent.devise.*;
      import demo.ejbent.resp.*;

      public interface Gprd extends EJBObject
      {
      public Integer getGprdId() throws RemoteException;
      public BigDecimal getRaysId() throws RemoteException;
      public Integer getFourId() throws RemoteException;
      public String getGprdLib() throws RemoteException;
      public Integer getDevId() throws RemoteException;


      //CMRs field
      public Devise getDeviseCMR()throws RemoteException;
      public void setDeviseCMR(Devise d)throws RemoteException;

      public Resp getResp()throws RemoteException;
      public void setResp(Resp r)throws RemoteException;
      }
      /***************************************************************************/
      Is there anything missing in this code ?

      Any suggestion is welcomed ....

      thanx !

        • 1. Re: One to Many relationship problem
          Leo Chan Newbie

          I have the same problem when I trying to implement one to Many relationship. Also when I try to call the a getSections() to return a collection, I get the following exception:
          [junit] java.lang.reflect.UndeclaredThrowableException: java.io.NotSerializa
          bleException: org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet
          [junit] at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServe
          r(StreamRemoteCall.java:245)
          [junit] at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCa
          ll.java:220)
          [junit] at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
          [junit] at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker_Stub.i
          nvoke(Unknown Source)
          [junit] at org.jboss.ejb.plugins.jrmp.interfaces.GenericProxy.invokeCont
          ainer(GenericProxy.java:369)
          [junit] at org.jboss.ejb.plugins.jrmp.interfaces.EntityProxy.invoke(Enti
          tyProxy.java:133)
          [junit] at $Proxy3.getSections(Unknown Source)
          [junit] at com.qxform.unittest.SectionEntityTest.testSection(SectionEnti
          tyTest.java:62)

          I am not sure why. I tried the example from the JBoss-CMP-docs, it worked okay for the one to many relationship (Order-lineitem). I am not sure why it works in the example but not for my program. Anyone knows what the problem is, please help!

          • 2. Re: One to Many relationship problem
            Leo Chan Newbie

            I found out what the problem is. The problem is that for CMR (Container Managed relationship), we can't use remoteinterface. It must be EJBLocalObject instead of EJBObject. That sucks!

            • 3. Re: One to Many relationship problem
              Torsten Schlumm Newbie

              Perhaps it sucks (why?) but if I understand the
              EJB spec right then you have to use local interfaces.

              sect. 10.3.10.1 (Restrictions on remote interfaces)
              ...
              The Bean Provider must not expose the get and
              set methods for container-managed relationship
              fields or the persistent Collection classes that
              are used in container-managed relationships
              through the remote interface of the bean.
              ...


              I hope this is correct (Dain??) if not simply ignore
              me.

              Cheers,
              Torsten

              • 4. Re: One to Many relationship problem
                Leo Chan Newbie

                You are correct about the spec. JBoss is just following the spec. I am saying that it sucks that CMR can only work local interface.

                • 5. Re: One to Many relationship problem
                  Carole.D Newbie

                  Hi ;
                  I changed my remote interface to extends EJBLocalObject as following:
                  /**************************************/
                  package demo.ejbent.gprd;

                  import java.rmi.*;
                  import javax.ejb.*;
                  import java.math.*;
                  import java.sql.*;
                  import java.util.*;
                  import demo.ejbent.devise.*;
                  import demo.ejbent.resp.*;

                  public interface Gprd extends EJBLocalObject
                  {
                  public Integer getGprdId() ;
                  public BigDecimal getRaysId() ;
                  public Integer getFourId() ;
                  public String getGprdLib();
                  public Integer getDevId() ;
                  // public BigDecimal getRespId() throws RemoteException;


                  //CMRs fields
                  public Devise getDeviseCMR();
                  public void setDeviseCMR(Devise d);

                  public Resp getResp();
                  public void setResp(Resp r);
                  }
                  /***************************************/
                  and the same for my home interface it exends EJBLocalHome
                  but once I try to deploy it I got the following error:
                  /************************************/
                  [10:21:59,167,ContainerFactory] Could not deploy file:/C:/jboss-3.0.0alpha/deploy/Default/JBossSource.jar/
                  org.jboss.ejb.DeploymentException: Could not find matching method for public abstract void javax.ejb.EJBLocalObject.remove() throws javax.ejb.RemoveException,ja
                  vax.ejb.EJBException, Cause: java.lang.NoSuchMethodException

                  at org.jboss.ejb.EntityContainer.setupBeanMappingImpl(EntityContainer.java:850)
                  at org.jboss.ejb.EntityContainer.setupBeanMapping(EntityContainer.java:863)
                  at org.jboss.ejb.EntityContainer.init(EntityContainer.java:297)
                  at org.jboss.ejb.Application.start(Application.java:201)
                  at org.jboss.ejb.ContainerFactory.deploy(ContainerFactory.java:382)
                  at org.jboss.ejb.ContainerFactory.deploy(ContainerFactory.java:308)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1628)
                  at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
                  at org.jboss.deployment.J2eeDeployer.startModules(J2eeDeployer.java:467)
                  at org.jboss.deployment.J2eeDeployer.startApplication(J2eeDeployer.java:444)
                  at org.jboss.deployment.J2eeDeployer.deploy(J2eeDeployer.java:215)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1628)
                  at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
                  at org.jboss.deployment.AutoDeployer.deploy(AutoDeployer.java:654)
                  at org.jboss.deployment.AutoDeployer.run(AutoDeployer.java:327)
                  at java.lang.Thread.run(Thread.java:484)
                  [10:21:59,348,J2eeDeployer#Default] Starting JBossSource.jar failed!
                  javax.management.RuntimeMBeanException: RuntimeException thrown in operation deploy
                  at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1640)
                  at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
                  at org.jboss.deployment.J2eeDeployer.startModules(J2eeDeployer.java:467)
                  at org.jboss.deployment.J2eeDeployer.startApplication(J2eeDeployer.java:444)
                  at org.jboss.deployment.J2eeDeployer.deploy(J2eeDeployer.java:215)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1628)
                  at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
                  at org.jboss.deployment.AutoDeployer.deploy(AutoDeployer.java:654)
                  at org.jboss.deployment.AutoDeployer.run(AutoDeployer.java:327)
                  at java.lang.Thread.run(Thread.java:484)
                  [10:21:59,458,J2eeDeployer#Default] Module JBossSource.jar is not running
                  [10:21:59,478,J2eeDeployer#Default] Destroying application JBossSource.jar
                  [10:21:59,488,J2eeDeployer#Default] Destroyed
                  [10:21:59,498,AutoDeployer] Deployment failed:file:/C:/jboss-3.0.0alpha/deploy/JBossSource.jar
                  org.jboss.deployment.J2eeDeploymentException: Error while starting JBossSource.jar: null, Cause: java.lang.NullPointerException
                  at org.jboss.deployment.J2eeDeployer.startModules(J2eeDeployer.java:529)
                  at org.jboss.deployment.J2eeDeployer.startApplication(J2eeDeployer.java:444)
                  at org.jboss.deployment.J2eeDeployer.deploy(J2eeDeployer.java:215)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1628)
                  at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
                  at org.jboss.deployment.AutoDeployer.deploy(AutoDeployer.java:654)
                  at org.jboss.deployment.AutoDeployer.run(AutoDeployer.java:327)
                  at java.lang.Thread.run(Thread.java:484)


                  /*******************************************/

                  Even that the ejbRemove() exists in the bean class!!
                  I tried to put the remove() in the remote interface but the error persists
                  WHY ????????

                  thanx for help :)