5 Replies Latest reply on Feb 27, 2002 12:09 AM by Dain Sundstrom

    Load relation failed

    Steve Knight Newbie

      Hello,
      I am trying to get a simple CMR example working. I have two tables: Parent(parentid, name) & Child(childid, name, parentid) with a one-to-many relationship.

      My jar deploys fine, but when I try to get the collection of children for a Parent I get the following error:

      Got ParentHome
      The Parent is:
      1 John Smith
      Children are:
      java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
      java.rmi.ServerException: Load relation failed
      Embedded Exception
      Syntax error or access violation: You have an error in your SQL syntax near 'FROM Parent WHERE (parentid=1)' at line 1;


      My client is calling a remote getChildren() method which simply calls the Parent's cmr accessor getChilds(), puts everything into a Collection of Child Data objects, and returns them.
      From the error given, it is obvious that the SQL generated by the container for this relationship is incorrect...maybe "Parent" should be "Child"???

      I am using XDoclet to generate my classes with the help of the CMP Documentation and it would appear as though my docs are out of date.
      Does anyone have a WORKING example of cmr??? I am very confused on what to put in the various config files. Or at least can you show me what the CURRENT jbosscmp-jdbc tags are and how they're used? I've tried tweaking my jbosscmp-jdbc.xml but I just end up with other relationship errors.

      I have attached my current jbosscmp-jdbc.xml

      Thanks a lot,

      Steve

        • 1. Re: Load relation failed
          Steve Knight Newbie

          Actually, the jbosscmp-jdbc.xml that I attached generates a different error, as follows:


          org.jboss.deployment.DeploymentException: Role: one-child-belongs-to-one-parent
          with multiplicity many using foreign-key mapping is not allowed to have key-fiel
          ds
          at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationshipRoleMetaData.
          loadKeyFields(JDBCRelationshipRoleMetaData.java:352)
          at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationshipRoleMetaData.
          init(JDBCRelationshipRoleMetaData.java:157)
          at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationMetaData.(J
          DBCRelationMetaData.java:308)
          at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCApplicationMetaData.(JDBCApplicationMetaData.java:383)
          at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCXmlFileLoader.load(JDBCXm
          lFileLoader.java:75)
          at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadJDBCEntityMetaDat
          a(JDBCStoreManager.java:503)
          at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.create(JDBCStoreManag
          er.java:277)
          at org.jboss.ejb.plugins.CMPPersistenceManager.create(CMPPersistenceMana
          ger.java:134)
          at org.jboss.ejb.EntityContainer.create(EntityContainer.java:342)
          at org.jboss.ejb.Application.start(Application.java:214)
          at org.jboss.ejb.EJBDeployer.deploy(EJBDeployer.java:431)
          at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:396)
          at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:362)
          at org.jboss.deployment.MainDeployer.scan(MainDeployer.java:243)
          at org.jboss.deployment.MainDeployer.startService(MainDeployer.java:196)

          at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:1
          30)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:16
          28)
          at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:15
          23)
          at org.jboss.system.Server.(Server.java:182)
          at org.jboss.Main.boot(Main.java:243)
          at org.jboss.Main.run(Main.java:44)
          at java.lang.Thread.run(Unknown Source)
          02:34:27,665 WARN [MainDeployer] operation failed; ignoring
          java.lang.NullPointerException
          at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.stop(JDBCStoreManager
          .java:346)
          at org.jboss.ejb.plugins.CMPPersistenceManager.stop(CMPPersistenceManage
          r.java:180)
          at org.jboss.ejb.EntityContainer.stop(EntityContainer.java:408)
          at org.jboss.ejb.Application.stop(Application.java:240)
          at org.jboss.ejb.EJBDeployer.deploy(EJBDeployer.java:444)
          at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:396)
          at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:362)
          at org.jboss.deployment.MainDeployer.scan(MainDeployer.java:243)
          at org.jboss.deployment.MainDeployer.startService(MainDeployer.java:196)

          at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:1
          30)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:16
          28)
          at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:15
          23)
          at org.jboss.system.Server.(Server.java:182)
          at org.jboss.Main.boot(Main.java:243)
          at org.jboss.Main.run(Main.java:44)
          at java.lang.Thread.run(Unknown Source)


          Any ideas???
          Thanks,

          Steve

          • 2. Re: Load relation failed
            Georg Schmid Newbie

            I guess you are using a recent version of RH.
            The jbosscmp-jdbc.xml format has changed.

            - foreign-key-mapping is now only a flag (an empty element).
            - foreign-key-field(s) has become key-field(s).
            - And you have to remove the settings for the relationship
            field name. It is now generated automatically from the cmr field name (I don't know whether this can be controlled, see commented-out part below).

            <ejb-relation>
            <ejb-relation-name>Master-Detail</ejb-relation-name>
            <foreign-key-mapping/>
            <ejb-relationship-role>
            <ejb-relationship-role-name>master-has-details</ejb-relationship-role-name>
            <key-fields/>
            </ejb-relationship-role>
            <ejb-relationship-role>
            <ejb-relationship-role-name>detail-belongs-to-master</ejb-relationship-role-name>
            <!--
            <key-fields>
            <key-field>
            <field-name>id</field-name>
            <column-name>FK_MASTER_ID</column-name>
            </key-field>
            </key-fields>
            -->
            </ejb-relationship-role>
            </ejb-relation>

            If you have 1:1 relationships, the fk field is now generated in the other table (so changing foreign-key-field to key-field by search-replace is not enough).

            HTH.

            Georg

            • 3. Re: Load relation failed
              Steve Knight Newbie

              Georg, thanks for the help!

              Jboss doesn't want to let me put in the key-fields...it complains that they don't belong there, even when I change the column-name.

              So, I just put in <key-fields/> for both sides of the relationship and tried it using the Default Hypersonic database instead. It gave the same error but included more info:

              Listening for transport dt_socket at address: 1445
              Getting ParentHome
              Got ParentHome
              The Parent is:
              1 John Smith
              Children are:
              java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
              java.rmi.ServerException: Load relation failed
              Embedded Exception
              Unexpected token: FROM in statement [SELECT FROM parent WHERE (parentid=1)]; nested exception is:
              javax.ejb.EJBException: Load relation failed
              Embedded Exception
              Unexpected token: FROM in statement [SELECT FROM parent WHERE (parentid=1)]


              I am not sure what the container is trying to do with this query but it is clearly wrong...it's not selecting anything!

              I must have something configured wrong.

              Any other ideas?
              Thanks,

              Steve

              • 4. Re: Load relation failed
                Georg Schmid Newbie

                It seems there's actually a bug in the SQL generated
                by JDBCLoadRelationCommand.

                It creates something like
                select ID, from YourTableNameHere

                whith the comma after the id being incorrect.

                If you set the default logging level in log4j.properties
                to DEBUG you may be able to see the statement in the
                server log just a few lines above the exception.

                I guess we have to wait for a fix.

                Dain, any ideas on this?

                Georg

                • 5. Re: Load relation failed
                  Dain Sundstrom Master

                  Do you still have this problem?

                  If so please post a bug report.