6 Replies Latest reply on May 18, 2004 4:24 PM by ignacio cuesta

    simplest one-to-one relationships bug

    ignacio cuesta Newbie

      Hi all!!
      I've 2 tables that contain the same primary key (docid)
      and both have diferent fileds for a document
      One of that has all the basic fields for a document and the other has metadata for the same document.
      Obviously the relation is one-to-one
      well, the names of the beans are : EDocuments and EDocMetaData

      This is the code for EDocuments:
      /**
      * @ejb.bean name="EDocuments"
      * jndi-name="EDocumentsBean"
      * type="CMP"
      * schema="documents"
      * cmp-version="2.x"
      * primkey-field="docid"
      *
      * @ejb.persistence
      * table-name="documents"
      *
      * @ejb.finder
      * query="SELECT OBJECT(a) FROM documents as a"
      * signature="java.util.Collection findAll()"
      **/

      /**
      * @ejb.interface-method
      *
      * @ejb.relation
      * name="EDocuments-EDocMetaData"
      * role-name="EDocuments-has-one-EDocMetadata"
      *
      * @jboss.relation
      * related-pk-field="docid"
      * fk-column="docid"
      *
      */

      public abstract EDocMetaData getEDocMetaData();
      /**
      * @ejb.interface-method
      * view-type="both"
      */
      public abstract void setEDocMetaData(EDocMetaData metaData);


      and this is for EDocMetaData bean :
      /**
      * @ejb.bean name="EDocMetaData"
      * jndi-name="EDocMetaDataBean"
      * type="CMP"
      * primkey-field="docid"
      * schema="docmetadata"
      * cmp-version="2.x"
      *
      * @ejb.persistence
      * table-name="docmetadata"
      *
      * @ejb.finder
      * query="SELECT OBJECT(a) FROM docmetadata as a"
      * signature="java.util.Collection findAll()"
      *
      **/

      /**
      * @ejb.interface-method
      *
      * @ejb.relation
      * name="EDocuments-EDocMetaData"
      * role-name="EDocMetadata-has-one-EDocuments"
      * @jboss.relation
      * related-pk-field="docid"
      * fk-column="docid"
      */

      public abstract EDocuments getEDocuments();
      public abstract void setEDocuments(EDocuments document);

      This is the code for ejb-jar.xml

      <!-- Relationships -->

      <ejb-relation >
      <ejb-relation-name>EDocuments-EDocMetaData</ejb-relation-name>

      <ejb-relationship-role >
      <ejb-relationship-role-name>EDocuments-has-one-EDocMetadata
      </ejb-relationship-role-name>
      One
      <relationship-role-source >
      <ejb-name>EDocuments</ejb-name>
      </relationship-role-source>
      <cmr-field >
      <cmr-field-name>EDocMetaData</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>

      <ejb-relationship-role >
      <ejb-relationship-role-name>EDocMetadata-has-one-EDocuments</ejb-relationship-role-name>
      One
      <relationship-role-source >
      <ejb-name>EDocMetaData</ejb-name>
      </relationship-role-source>
      <cmr-field >
      <cmr-field-name>eocuments</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>

      </ejb-relation>



      and this is for jbosscmp-jdbc


      <ejb-relation>
      <ejb-relation-name>EDocuments-EDocMetaData</ejb-relation-name>

      <foreign-key-mapping/>

      <ejb-relationship-role>
      <ejb-relationship-role-name>EDocuments-has-one-EDocMetadata</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>docid</field-name>
      <column-name>docid</column-name>
      </key-field>
      </key-fields>

      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>EDocMetadata-has-one-EDocuments</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>docid</field-name>
      <column-name>docid</column-name>
      </key-field>
      </key-fields>

      </ejb-relationship-role>
      </ejb-relation>



      Well,
      Finally I'm using Lomboz for generate all deploy files and
      all the file were generated well and the deploy files were good too.
      But when I want to use the client tester like this :

      public class DocumentsTest {

      private com.Entrieva.Skyline.SessionBeans.SDocumentsHome getHome()
      throws NamingException {
      return (com.Entrieva.Skyline.SessionBeans.SDocumentsHome) getContext().lookup(
      com.Entrieva.Skyline.SessionBeans.SDocumentsHome.JNDI_NAME);
      }
      private InitialContext getContext() throws NamingException {
      Hashtable props = new Hashtable();
      props.put(InitialContext.INITIAL_CONTEXT_FACTORY,
      "org.jnp.interfaces.NamingContextFactory");
      props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
      InitialContext initialContext = new InitialContext(props);
      return initialContext;
      }
      public void testBean() throws CreateException, RemoteException, FinderException {

      try {
      SDocuments myBean = getHome().create();
      Collection col = myBean.getAllDocumentByCategoryId(11);
      // get all documents by category
      Iterator iter = col.iterator();
      while (iter.hasNext()) {
      EDocuments element = ((EDocuments) iter.next());
      System.out.println("Abstract:" + element.getShortabstract());
      EDocMetaData meta = element.getEDocMetaData();}
      } catch (NamingException e) {
      e.printStackTrace();
      }
      }

      public static void main(String[] args) throws RemoteException, CreateException, FinderException {
      DocumentsTest test = new DocumentsTest();
      test.testBean();
      }

      this bugs appear in the console:
      java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
      java.rmi.ServerException: RuntimeException; nested exception is:
      java.lang.ClassCastException
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:292)
      at sun.rmi.transport.Transport$1.run(Transport.java:148)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
      at java.lang.Thread.run(Thread.java:536)
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
      at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
      at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:135)
      at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:96)
      at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:45)
      at org.jboss.proxy.ejb.EntityInterceptor.invoke(EntityInterceptor.java:97)
      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
      at $Proxy2.getEDocMetaData(Unknown Source)
      at com.neoris.Test.DocumentsTest.testBean(DocumentsTest.java:58)
      at com.neoris.Test.DocumentsTest.main(DocumentsTest.java:67)


      Thanks in advance any help !!!!!

        • 1. Re: simplest one-to-one relationships bug
          ignacio cuesta Newbie

          ava.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
          java.rmi.ServerException: RuntimeException; nested exception is:
          java.lang.ClassCastException
          at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:292)
          at sun.rmi.transport.Transport$1.run(Transport.java:148)
          at java.security.AccessController.doPrivileged(Native Method)
          at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
          at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
          at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
          at java.lang.Thread.run(Thread.java:536)
          at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
          at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
          at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
          at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
          at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:135)
          at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:96)
          at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
          at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:45)
          at org.jboss.proxy.ejb.EntityInterceptor.invoke(EntityInterceptor.java:97)
          at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
          at $Proxy2.getEDocMetaData(Unknown Source)
          at com.neoris.Test.DocumentsTest.testBean(DocumentsTest.java:67)
          at com.neoris.Test.DocumentsTest.main(DocumentsTest.java:77)
          Caused by: java.rmi.ServerException: RuntimeException; nested exception is:
          java.lang.ClassCastException
          at org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.java:361)
          at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
          at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
          at org.jboss.ejb.EntityContainer.internalInvoke(EntityContainer.java:489)
          at org.jboss.ejb.Container.invoke(Container.java:700)
          at sun.reflect.GeneratedMethodAccessor184.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:324)
          at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
          at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
          at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:367)
          at sun.reflect.GeneratedMethodAccessor136.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:324)
          at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
          at sun.rmi.transport.Transport$1.run(Transport.java:148)
          at java.security.AccessController.doPrivileged(Native Method)
          at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
          at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
          at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
          at java.lang.Thread.run(Thread.java:536)
          Caused by: java.lang.ClassCastException
          at com.Entrieva.Skyline.EntityBeans.EDocumentsCMP$Proxy.getEDocMetaData()
          at sun.reflect.GeneratedMethodAccessor209.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:324)
          at org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke(EntityContainer.java:1096)
          at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke(JDBCRelationInterceptor.java:72)
          at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:282)
          at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
          at org.jboss.ejb.plugins.EntityReentranceInterceptor.invoke(EntityReentranceInterceptor.java:114)
          at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:163)
          at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:89)
          at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:54)
          at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
          at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:267)
          at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:128)
          at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:118)
          at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
          ... 19 more



          that's the complete bug

          • 2. Re: simplest one-to-one relationships bug
            ignacio cuesta Newbie

            My Problem was because I didn't use a Local Interface.
            Ok , I just use
            EDocMetaDataLocal meta = element.getEDocMetaData();
            but when I want to use any filed for example:
            System.out.println(meta.getAuthor());
            this error appear:

            java.lang.NullPointerException
            at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)
            at $Proxy4.getAuthor(Unknown Source)
            at com.neoris.Test.DocumentsTest.testBean(DocumentsTest.java:60)
            at com.neoris.Test.DocumentsTest.main(DocumentsTest.java:70)
            Exception in thread "main"

            • 3. Re: simplest one-to-one relationships bug
              Darran Lofthouse Master

              Remote clients can not make use of the Local interfaces.

              • 4. Re: simplest one-to-one relationships bug
                ignacio cuesta Newbie

                so, how can I get the fields from the other bean that participate in the relationships ?

                while (iter.hasNext()) {
                EDocuments element = ((EDocuments) iter.next());
                System.out.println("Abstract:" + element.getShortabstract());
                EDocMetaDataLocal meta = element.getEDocMetaData();
                System.out.println(meta.getAuthor()[/color]);
                }

                • 5. Re: simplest one-to-one relationships bug
                  ignacio cuesta Newbie

                  somebody knows some tutorial to create one-to-one relationships ?
                  thanks in advance

                  • 6. Re: simplest one-to-one relationships bug
                    ignacio cuesta Newbie

                    SDocuments myBean2;
                    myBean2 = getHome().create();
                    Collection col = myBean2.getAllDocumentByCategoryId(11);
                    Iterator iter = col.iterator();
                    while (iter.hasNext()) {
                    EDocuments element = ((EDocuments) iter.next());
                    System.out.println(element.getEDocMetaData());
                    }

                    the result of the code is :
                    EDocMetaDataLocal:35
                    EDocMetaDataLocal:69
                    EDocMetaDataLocal:86

                    but when I want to get some field ....
                    System.out.println(element.getEDocMetaData().getAuthor());
                    this error appear:

                    java.lang.NullPointerException
                    at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)
                    at $Proxy4.getAuthor(Unknown Source)
                    at com.neoris.Test.DocumentsTest.testBean(DocumentsTest.java:63)
                    at com.neoris.Test.DocumentsTest.main(DocumentsTest.java:69)
                    Exception in thread "main"