1 Reply Latest reply on Jan 20, 2002 12:26 PM by Dain Sundstrom

    Relationship mapping problem

    Ralf Ebert Newbie

      Hello,

      I tried the relationship mapping of CMP2.0 and I just can't get it working. I have a table for all countries of the world, with an primary key Land_Id. Then I have a table with adresses. This table has a field Land_Id for specifiying one country for each adress. I wanted jBoss 3.0 alpha to map that relationship. I have two entity beans, one for the adresses, one for the countries. I added the following methods in the entity bean for the adress:

      public abstract Land getLand();
      public abstract void setLand(Land aLand);

      And in the entity bean for the country:

      public abstract Collection getAdressen();
      public abstract void setAdressen(Collection Adressen);

      I didn't declared the Land-field in the ejb-jar.xml for the adress entity bean, because that didn't seem to be the right thing. Then I added the relationships to my ejb-jar.xml:


      <ejb-relation>
      <ejb-relation-name>Adresse-Land</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>land-hat-adressen</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>intrablue_Land</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>Adressen</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>adressen-haben-land</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>intrablue_Adresse</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>Land</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      </ejb-relation>


      and to the jbosscmp-jdbc.xml:


      <ejb-relation>
      <ejb-relation-name>Adresse-Land</ejb-relation-name>
      <foreign-key-mapping>
      <ejb-relationship-role>
      <ejb-relationship-role-name>land-hat-adressen</ejb-relationship-role-name>
      <fk-constraint>false</fk-constraint>
      <foreign-key-fields/>
      </ejb-relationship-role>

      <ejb-relationship-role>
      <ejb-relationship-role-name>adressen-haben-land</ejb-relationship-role-name>
      <fk-constraint>false</fk-constraint>
      <foreign-key-fields>
      <foreign-key-field>
      <field-name>Land_Id</field-name>
      <column-name>Land_Id</column-name>
      </foreign-key-field>
      </foreign-key-fields>

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



      But everytime I try to use getLand() from the client now, it doesn't work! I just get an null pointer exception like this:

      [10:28:43,706,Default] java.lang.NullPointerException
      [10:28:43,706,Default] at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker
      .getEntityEJBLocalObject(BaseLocalContainerInvoker.java:226)
      [10:28:43,716,Default] at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBri
      dge.getValue(JDBCCMRFieldBridge.java:399)
      [10:28:43,716,Default] at org.jboss.ejb.plugins.cmp.bridge.EntityBridgeInvocati
      onHandler.invoke(EntityBridgeInvocationHandler.java:111)
      [10:28:43,716,Default] at org.jboss.proxy.ProxyCompiler$Runtime.invoke(ProxyCom
      piler.java:89)
      [10:28:43,726,Default] at server.adressen.adresse.AdresseBean$Proxy.getLand(Unk
      nown Source)
      [10:28:43,726,Default] at java.lang.reflect.Method.invoke(Native Method)
      [10:28:43,726,Default] at org.jboss.ejb.EntityContainer$ContainerInterceptor.in
      voke(EntityContainer.java:1002)
      [10:28:43,726,Default] at org.jboss.ejb.plugins.cmp.jdbc.JDBCReadAheadIntercept
      or.invoke(JDBCReadAheadInterceptor.java:100)
      [10:28:43,736,Default] at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationIntercepto
      r.invoke(JDBCRelationInterceptor.java:134)
      [10:28:43,736,Default] at org.jboss.ejb.plugins.EntitySynchronizationIntercepto
      r.invoke(EntitySynchronizationInterceptor.java:308)
      [10:28:43,736,Default] at org.jboss.ejb.plugins.EntityInstanceInterceptor.invok
      e(EntityInstanceInterceptor.java:201)
      [10:28:43,746,Default] at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(En
      tityLockInterceptor.java:132)
      [10:28:43,746,Default] at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNex
      t(AbstractTxInterceptor.java:98)
      [10:28:43,756,Default] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransac
      tions(TxInterceptorCMT.java:156)
      [10:28:43,756,Default] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInter
      ceptorCMT.java:65)
      [10:28:43,756,Default] at org.jboss.ejb.plugins.SecurityInterceptor.invoke(Secu
      rityInterceptor.java:131)
      [10:28:43,756,Default] at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterc
      eptor.java:166)
      [10:28:43,766,Default] at org.jboss.ejb.EntityContainer.invoke(EntityContainer.
      java:447)
      [10:28:43,766,Default] at org.jboss.ejb.Container.invoke(Container.java:528)
      [10:28:43,766,Default] at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanSe
      rverImpl.java:1555)
      [10:28:43,776,Default] at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanSe
      rverImpl.java:1523)
      [10:28:43,776,Default] at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoke
      r.invoke(JRMPContainerInvoker.java:411)
      [10:28:43,776,Default] at java.lang.reflect.Method.invoke(Native Method)
      [10:28:43,786,Default] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServe
      rRef.java:241)
      [10:28:43,786,Default] at sun.rmi.transport.Transport$1.run(Transport.java:152)

      [10:28:43,786,Default] at java.security.AccessController.doPrivileged(Native Me
      thod)
      [10:28:43,786,Default] at sun.rmi.transport.Transport.serviceCall(Transport.jav
      a:148)
      [10:28:43,796,Default] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCP
      Transport.java:465)
      [10:28:43,796,Default] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.
      run(TCPTransport.java:706)
      [10:28:43,796,Default] at java.lang.Thread.run(Thread.java:484)
      [10:28:43,806,EntityContainer] invoke returned an exception
      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(JDB
      CCMRFieldBridge.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 server.adressen.adresse.AdresseBean$Proxy.getLand(Unknown Source)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke(EntityConta
      iner.java:1002)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCReadAheadInterceptor.invoke(JDBCRe
      adAheadInterceptor.java:100)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke(JDBCRel
      ationInterceptor.java:134)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntityS
      ynchronizationInterceptor.java:308)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstance
      Interceptor.java:201)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockIntercep
      tor.java:132)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
      rceptor.java:98)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:156)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:6
      5)
      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:15
      55)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:15
      23)
      at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPCon
      tainerInvoker.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: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:4
      65)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
      .java:706)
      at java.lang.Thread.run(Thread.java:484)
      java.lang.NullPointerException
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.getEntityEJBLoc
      alObject(BaseLocalContainerInvoker.java:226)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.getValue(JDB
      CCMRFieldBridge.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 server.adressen.adresse.AdresseBean$Proxy.getLand(Unknown Source)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke(EntityConta
      iner.java:1002)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCReadAheadInterceptor.invoke(JDBCRe
      adAheadInterceptor.java:100)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke(JDBCRel
      ationInterceptor.java:134)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntityS
      ynchronizationInterceptor.java:308)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstance
      Interceptor.java:201)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockIntercep
      tor.java:132)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
      rceptor.java:98)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:156)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:6
      5)
      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:15
      55)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:15
      23)
      at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPCon
      tainerInvoker.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: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:4
      65)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
      .java:706)
      at java.lang.Thread.run(Thread.java:484)


      What's wrong with the relationship mapping in my example ?
      Thanks in advance!
      Regards,
      Ralf

        • 1. Re: Relationship mapping problem
          Dain Sundstrom Master

          Your foreign key mapping is wrong. You have:

          <foreign-key-fields>
          <foreign-key-field>
          <field-name>Land_Id</field-name>
          <column-name>Land_Id</column-name>
          </foreign-key-field>
          </foreign-key-fields>

          The foreign key field-name in this case must be the same as the primkey-field of intrablue_Land. You have Land_Id, but that is not possible because field-names must begin with a lower case character.