11 Replies Latest reply on May 20, 2002 11:40 PM by Dain Sundstrom

    CMP field for key not found (CMR,JBossRC1,XDoclet)

    Grzeschik, Peter Newbie

      I have a problem which i can't cope with.

      0RC1_tomcat-4.0.3/server/default/deploy/CommonAttribute.jar/96.CommonAttribute.jar!/META-INF/jbosscmp-jdbc.xml found. Overriding defaults
      10:47:59,747 ERROR [EntityContainer] Exception in service lifecyle operation: create
      org.jboss.deployment.DeploymentException: CMP field for key not found: field name=id
      at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationshipRoleMetaData.loadKeyFields(JDBCRelationshipRoleMetaData.java:374)
      at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationshipRoleMetaData.init(JDBCRelationshipRoleMetaData.java:157)
      at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationMetaData.(JDBCRelationMetaData.java:309)
      at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCApplicationMetaData.(JDBCApplicationMetaData.java:383)
      at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCXmlFileLoader.load(JDBCXmlFileLoader.java:75)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadJDBCEntityMetaData(JDBCStoreManager.java:595)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.create(JDBCStoreManager.java:322)
      at org.jboss.ejb.plugins.CMPPersistenceManager.create(CMPPersistenceManager.java:155)
      at org.jboss.ejb.EntityContainer.create(EntityContainer.java:337)
      at org.jboss.ejb.Container.invoke(Container.java:790)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1055)
      ...

      My jbosscmp-jdbc.xml:
      <jbosscmp-jdbc>

      java:/OracleDS
      <datasource-mapping>Oracle8</datasource-mapping>


      <enterprise-beans>


      <ejb-name>attribute/Attribute</ejb-name>
      <create-table>false</create-table>
      <remove-table>false</remove-table>
      <table-name>ATTRIBUTE</table-name>

      <cmp-field>
      <field-name>id</field-name>
      <column-name>ID</column-name>
      <jdbc-type>BIGINT</jdbc-type>
      <sql-type>NUMBER(19)</sql-type>
      ...



      <ejb-name>attribute/StringAttribute</ejb-name>
      <create-table>false</create-table>
      <remove-table>false</remove-table>
      <table-name>ATTRIBUTE_VAL_STRING</table-name>

      <cmp-field>
      <field-name>id</field-name>
      <column-name>ID</column-name>
      <jdbc-type>BIGINT</jdbc-type>
      <sql-type>NUMBER(19)</sql-type>
      ...



      </enterprise-beans>


      <ejb-relation>
      <ejb-relation-name>link_to_identifier</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>link_to_identifier_FK_role</ejb-relationship-role-name>
      <fk-constraint>false</fk-constraint>
      <key-fields/>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>link_to_identifier_PK_role</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>id</field-name>
      <column-name></column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      </ejb-relation>

      ...
      </jbosscmp-jdbc>

      My ejb-jar.xml:
      ...
      <enterprise-beans>
      ...

      <display-name>Attribute</display-name>

      <ejb-name>attribute/Attribute</ejb-name>
      ...
      <persistence-type>Container</persistence-type>
      false
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Attribute</abstract-schema-name>
      <cmp-field >
      <![CDATA[Get ID]]>
      <field-name>id</field-name>
      </cmp-field>
      ...



      <display-name>StringAttribute</display-name>

      <ejb-name>attribute/StringAttribute</ejb-name>
      ...
      <cmp-field >
      <![CDATA[Get ID]]>
      <field-name>id</field-name>
      </cmp-field>
      ...
      </enterprise-beans>
      ...
      <!-- Relationships -->

      <ejb-relation >
      <ejb-relation-name>link_to_identifier</ejb-relation-name>
      <!-- unidirectional -->
      <ejb-relationship-role >
      <ejb-relationship-role-name>link_to_identifier_FK_role</ejb-relationship-role-name>
      One
      <relationship-role-source >
      <ejb-name>attribute/StringAttribute</ejb-name>
      </relationship-role-source>
      <cmr-field >
      <cmr-field-name>id</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role >
      <ejb-relationship-role-name>link_to_identifier_PK_role</ejb-relationship-role-name>
      One
      <relationship-role-source >
      <ejb-name>attribute/Attribute</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>

      ...

      Database tables looks like:
      TABLE ATTRIBUTE
      (
      ID NUMBER(19,0) NOT NULL,
      ATT_PRODID NUMBER(19,0) NULL,
      ATT_KEY VARCHAR2(255) NULL,
      ATT_MEASURE VARCHAR2(255) NULL,

      PRIMARY KEY (ID),
      CHECK ("ID" IS NOT NULL)
      );
      TABLE ATTRIBUTE_VAL_STRING
      (
      ID NUMBER(19,0) NOT NULL,
      VAL_STRING VARCHAR2(255) NULL,

      PRIMARY KEY (ID),
      CHECK ("ID" IS NOT NULL)
      );

      All files were generated with XDoclet1.1.2
      Unfortunately I did not found any suitable solution for my problem.
      I hope you can help me.

      H.A.N.D.

        • 1. Re: CMP field for key not found (CMR,JBossRC1,XDoclet)
          Dain Sundstrom Master

          To start with, you have not defined a column name for the id key in the relationship in the jbosscmp-jdbc.xml file.

          I think the bigger problem is you are trying to map a cmr-field and cmp-field to the same column, which is not supported. It also looks like you are trying to use a cmr field as a primary key field, which is also not supported. Both of these will be supported in JBoss 3.1

          • 2. one role of a foreign-key mapped relationship must have key
            Grzeschik, Peter Newbie

            These are my first steps in CMR.
            I hope you can guide me through, or give me a working _complete_ example.

            Scenario / Survey:
            My goal is to get an one-2-one unidirectional relationship from StringAttribute --> Attribute.
            StringAttribute should be a superset of Attribute.

            Error:
            In my opinion i have a key-field given. I tried several variations the error is always the same even if I omit in jbosscmp-jdbc.xml.
            As a trial I've also omitted in ejb-jar.xml which causes SQL-statements like 'SELECT FROM ATTRIBUTE WHERE' ... which is also an error. Perhaps there is an other error, but as pure CMP-Beans my beans worked fine.

            15:38:54,558 ERROR [EntityContainer] Exception in service lifecyle operation: create
            org.jboss.deployment.DeploymentException: Atleast one role of a foreign-key mapped relationship must have key fields: ejb-relation-name=link
            _to_Attribute
            at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationMetaData.(JDBCRelationMetaData.java:316)
            at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCApplicationMetaData.(JDBCApplicationMetaData.java:325)
            at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCXmlFileLoader.load(JDBCXmlFileLoader.java:67)
            at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadJDBCEntityMetaData(JDBCStoreManager.java:595)
            at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.create(JDBCStoreManager.java:322)
            at org.jboss.ejb.plugins.CMPPersistenceManager.create(CMPPersistenceManager.java:155)
            at org.jboss.ejb.EntityContainer.create(EntityContainer.java:337)
            at org.jboss.ejb.Container.invoke(Container.java:790)
            at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1055)
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:492)
            at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:867)
            at $Proxy0.create(Unknown Source)
            at org.jboss.system.ServiceController.create(ServiceController.java:271)
            at java.lang.reflect.Method.invoke(Native Method)
            at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:492)
            at org.jboss.util.jmx.MBeanProxy.invoke(MBeanProxy.java:174)
            at $Proxy18.create(Unknown Source)
            ...

            My ejb-jar.xml:
            <ejb-jar >
            <!-- same as above -->
            ...
            <!-- Relationships -->

            <ejb-relation >
            <ejb-relation-name>link_to_Attribute</ejb-relation-name>
            <!-- unidirectional -->
            <ejb-relationship-role >
            <ejb-relationship-role-name>StringAttribute_hat_zugang_zu_Attribute</ejb-relationship-role-name>
            One
            <relationship-role-source >
            <ejb-name>attribute/StringAttribute</ejb-name>
            </relationship-role-source>
            <cmr-field >
            <!-- attribute is not a CMP-Field -->
            <cmr-field-name>attribute</cmr-field-name>
            </cmr-field>
            </ejb-relationship-role>
            <ejb-relationship-role >
            <ejb-relationship-role-name>Attribute_hat_zugang_zu_StringAttribute</ejb-relationship-role-name>
            One
            <relationship-role-source >
            <ejb-name>attribute/Attribute</ejb-name>
            </relationship-role-source>
            </ejb-relationship-role>
            </ejb-relation>

            ...

            My jbosscmp-jdbc.xml:
            <!-- same as above -->
            ...

            <ejb-relation>
            <ejb-relation-name>link_to_Attribute</ejb-relation-name>
            <foreign-key-mapping/>
            <ejb-relationship-role>
            <ejb-relationship-role-name>StringAttribute_hat_zugang_zu_Attribute</ejb-relationship-role-name>
            <key-fields>
            <key-field>
            <field-name>attribute</field-name>
            <column-name>ATT_ID</column-name>
            </key-field>
            </key-fields>
            </ejb-relationship-role>
            <ejb-relationship-role>
            <ejb-relationship-role-name>Attribute_hat_zugang_zu_StringAttribute</ejb-relationship-role-name>
            <fk-constraint>false</fk-constraint>
            <key-fields/>
            </ejb-relationship-role>
            </ejb-relation>

            ...

            My database-tables:
            TABLE ATTRIBUTE
            (
            <!-- same as above -->
            );

            TABLE ATTRIBUTE_VAL_STRING
            (
            ID NUMBER(19,0) NOT NULL,
            VAL_STRING VARCHAR2(255) NULL,
            ATT_ID NUMBER(19,0) NULL, <!-- used as FK -->

            PRIMARY KEY (ID),
            CHECK ("ID" IS NOT NULL)
            );

            • 3. Re: one role of a foreign-key mapped relationship must have
              Dain Sundstrom Master

              You have:

              <ejb-relationship-role>
               <ejb-relationship-role-name>StringAttribute_hat_zugang_zu_Attribute</ejb-relationship-role-name>
               <key-fields>
               <key-field>
               <field-name>attribute</field-name>
               <column-name>ATT_ID</column-name>
               </key-field>
               </key-fields>
              </ejb-relationship-role>
              

              In this section you are providing a mapping for the primary-keys of the current entity. attribute can not be the primary key field because it is your cmr-field. The field-name should be id.

              • 4. QL on CMR fails?
                Grzeschik, Peter Newbie

                Thanks,

                CMR is - i suppose - not an easy subject, so I have the next problem ... *SFT*
                Through my client i can only get the part which directy refers to the 'ATTRIBUTE_VAL_STRING' database table.

                As soon as I call StringAttributeRemoteObject.getAttribute() which should refer to ATTRIBUTE i got the following exception:

                RemoteException occurred in server thread; nested exception is:
                java.rmi.ServerException: null



                I tested this scenario with my findAll-method which uses "SELECT OBJECT(sa) FROM StringAttribute AS sa".
                The only query JBoss generates is "SELECT VAL_STRING, ATT_ID FROM ATTRIBUTE_VAL_STRING WHERE (ID=?)", which works.
                The tables of the database are not empty and the pk/fk-keys are set as required.
                So, where is the rest?

                • 5. Re: QL on CMR fails?
                  Dain Sundstrom Master

                  > Through my client i can only get the part which
                  > directy refers to the 'ATTRIBUTE_VAL_STRING' database
                  > table.

                  I have no idea what that means.

                  > As soon as I call
                  > StringAttributeRemoteObject.getAttribute()
                  > which should refer to ATTRIBUTE i got the following
                  > exception:
                  >
                  > RemoteException occurred in server thread; nested
                  > exception is:
                  > java.rmi.ServerException: null

                  This is your client exception, right? What is printed in the server.log file?

                  > I tested this scenario with my findAll-method which
                  > uses "SELECT OBJECT(sa) FROM StringAttribute AS
                  > sa".
                  > The only query JBoss generates is "SELECT VAL_STRING,
                  > ATT_ID FROM ATTRIBUTE_VAL_STRING WHERE (ID=?)", which
                  > works.
                  > The tables of the database are not empty and the
                  > pk/fk-keys are set as required.

                  FK columns can not be set as required (i.e., "NOT NULL).

                  > So, where is the rest?

                  The rest of what?



                  • 6. Re: QL on CMR fails?
                    Grzeschik, Peter Newbie

                    Sorry, I'm clumsy sometimes.

                    The client has access to the StringAttribute-Bean in which I only can access CMP-Fields. Each time I try to access the CMR-Field:'attribute' via getAttribute() I get a RemoteException on the client-side. So you are totally right, it is a client exception.

                    Regardless of the FK is NULL or NOT NULL, the same exception occur. By the way: JBoss initially created the database tables. Right after I disallow JBoss to do this, because I filled the tables with my records.

                    Here's an extract from the server.log:
                    [org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.attribute/StringAttribute.findAll] EJB-QL: SELECT OBJECT(sa) FROM StringAttribute AS sa
                    [org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.attribute/StringAttribute.findAll] SQL: SELECT t0_sa.ID FROM ATTRIBUTE_VAL_STRING t0_sa
                    [org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.attribute/StringAttribute.findAll] SQL: SELECT t0_sa.ID FROM ATTRIBUTE_VAL_STRING t0_sa
                    [org.jboss.resource.connectionmanager.CachedConnectionInterceptor] start called in CachedConnectionInterceptor
                    [org.jboss.ejb.EjbModule] Started
                    [org.jboss.ejb.EJBDeployer] Deployed: file:/D:/Programme/jboss-3.0.0RC1_tomcat-4.0.3/server/default/deploy/CommonAttribute.jar
                    [org.jboss.deployment.MainDeployer] Final (start) deployment step successfully completed on package: CommonAttribute.jar
                    [org.jboss.deployment.MainDeployer] Successfully completed deployment of package: file:/D:/Programme/jboss-3.0.0RC1_tomcat-4.0.3/server/default/deploy/CommonAttribute.jar
                    ...
                    ...
                    <!-- client call -->
                    [org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.attribute/StringAttribute.findAll] Executing SQL: SELECT t0_sa.ID FROM ATTRIBUTE_VAL_STRING t0_sa
                    [org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.attribute/StringAttribute] Executing SQL: SELECT VAL_STRING, ATT_ID FROM ATTRIBUTE_VAL_STRING WHERE (ID=?)
                    <!-- client call ends here -->
                    <!-- nothing -->

                    JBoss generates only this one SQL-statement which is only for exactly one table. So the 'rest' I expected are SQL-statements on the other table.

                    • 7. Re: QL on CMR fails?
                      Grzeschik, Peter Newbie

                      ... here's the server.log-file.

                      • 8. Re: QL on CMR fails?
                        Dain Sundstrom Master

                        Up the log level to trace to see the result set loaded into the container.

                        My guess is that it is not hooked up to the database you think. Try inserting some data and see if it appears in your database. If not, check the datasource specified in the jbosscmp-jdbc.xml file.

                        • 9. java.rmi.ServerException: null when calling CMR-relation get
                          Grzeschik, Peter Newbie

                          I inserted some data into the database, which works well. I still can't get the CMR-field data which is quite troublesome. I have no idea how to fix this nor what does this exception mean. Dain, can you help me?
                          Meanwhile I test my code also on jboss3.1alpha(CVS 04/29/02)

                          On DEBUG-level jboss only generates the following in my server.log :

                          DEBUG [findAll] Executing SQL: SELECT t0_sa.ID FROM ATTRIBUTE_VAL_STRING t0_sa
                          DEBUG [attribute/StringAttribute] Executing SQL: SELECT ID,VAL_STRING, ATT_ID FROM ATTRIBUTE_VAL_STRING WHERE (ID=?) OR (ID=?)
                          OR (ID=?)
                          DEBUG [attribute/StringAttribute] Executing SQL: SELECT ID,VAL_STRING, ATT_ID FROM ATTRIBUTE_VAL_STRING WHERE (ID=?) OR (ID=?)
                          OR (ID=?)

                          This is also the statement which I found in my database.log
                          SELECT ID,VAL_STRING, ATT_ID FROM ATTRIBUTE_VAL_STRING WHERE (ID=:1) OR (ID=:2)



                          My working ejb-jar.xml:

                          <!-- Relationships -->

                          <ejb-relation >
                          <ejb-relation-name>link_to_Attribute</ejb-relation-name>
                          <!-- unidirectional -->
                          <ejb-relationship-role >
                          <ejb-relationship-role-name>StringAttribute_has_one_Attribute</ejb-relationship-role-name>
                          One
                          <relationship-role-source >
                          <ejb-name>attribute/StringAttribute</ejb-name>
                          </relationship-role-source>
                          <cmr-field >
                          <cmr-field-name>attribute</cmr-field-name>
                          </cmr-field>
                          </ejb-relationship-role>
                          <ejb-relationship-role >
                          <ejb-relationship-role-name>Attribute_has_one_StringAttribute_that_is_not_accessible</ejb-relationship-role-name>
                          One
                          <relationship-role-source >
                          <ejb-name>attribute/Attribute</ejb-name>
                          </relationship-role-source>
                          </ejb-relationship-role>
                          </ejb-relation>



                          My working jbosscmp-jdbc.xml:


                          <ejb-relation>
                          <ejb-relation-name>link_to_Attribute</ejb-relation-name>
                          <foreign-key-mapping/>
                          <ejb-relationship-role>
                          <ejb-relationship-role-name>StringAttribute_has_one_Attribute</ejb-relationship-role-name>
                          <key-fields/>
                          </ejb-relationship-role>
                          <ejb-relationship-role>
                          <ejb-relationship-role-name>Attribute_has_one_StringAttribute_that_is_not_accessible</ejb-relationship-role-name>
                          <!-- This part confuses me, but works with the database. Shouldn't this be in the other role? -->
                          <key-fields>
                          <key-field>
                          <field-name>id</field-name>
                          <column-name>ATT_ID</column-name>
                          </key-field>
                          </key-fields>

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



                          This is the working snipplet I create new data in StringAttribute.java on server-side:

                          public AttributePK ejbCreate(java.lang.Long attId) throws javax.ejb.CreateException, javax.ejb.DuplicateKeyException
                          {
                          setId(attId);
                          return new AttributePK(attId);
                          }
                          public void ejbPostCreate(java.lang.Long attId)
                          {
                          Context ctx = new InitialContext();
                          AttributeLocalHome attLocalHome = (AttributeLocalHome) ctx.lookup("ejb/attribute/local/Attribute");
                          AttributeLocal attLocal = attLocalHome.create(attId);
                          attLocal.set...
                          setAttribute(attLocal);
                          }


                          This is the snipplet I receive data on client-side:

                          StringAttributeRemoteHome home = null;
                          String lookup = "ejb/attribute/StringAttribute";
                          Object ref = jndiContext.lookup(lookup);

                          home = (StringAttributeRemoteHome) PortableRemoteObject.narrow(ref, StringAttributeRemoteHome.class);
                          Collection coll = home.findAll();
                          if(coll != null)
                          {
                          Iterator iter = coll.iterator();
                          while(iter.hasNext())
                          {
                          StringAttributeRemote obj = (StringAttributeRemote) PortableRemoteObject.narrow(iter.next(), StringAttributeRemote.class);
                          <!-- getString() works on the CMP-field 'string' -->
                          System.out.println("String = " + obj.getString());
                          <!-- this part causes: javax.ejb.EJBException: null -->
                          System.out.println("Att = " + obj.getAttribute());
                          ...


                          The whole exception thrown on client-side:
                          String = hallo_1
                          RemoteException occurred in server thread; nested exception is:
                          java.rmi.ServerException: null
                          Embedded Exception
                          $Proxy38; nested exception is:
                          javax.ejb.EJBException: null
                          Embedded Exception
                          $Proxy38

                          • 10. Re: CMP field for key not found (CMR,JBossRC1,XDoclet)
                            Sundeep Kadakia Newbie

                            Hi dsundstrom,

                            You mentioned that mapping of CMR & CMP fields to same column will be available in JBoss 3.1. If I checkout today's src code and build that, will I get that feature. In other words, is it already implemented.

                            How can I checkout JBoss 3.1 HEAD, I have seen it's references around but could not understand whether it is a tag or not. So, to get the latest stuff, I issued the following command,
                            cvs checkout jboss-all
                            Do you think I have got the 3.1 HEAD tree.

                            Nonetheless, I have something which I believe is latest and built JBoss successfully, except for the catalina which still fails to build. It throws errors saying,
                            package javax.servlet does not exist
                            cannot resolve symbol
                            [javac]symbol : class XmlAction
                            I don't know how to define classpath and local.classpath in build.xml to let Ant know where the required jar files are.

                            <!-- classpath and local.classpath must have a value using with a path -->



                            Your help will be greatly appreciated.

                            Thank You.

                            Sundeep



                            • 11. Re: CMP field for key not found (CMR,JBossRC1,XDoclet)
                              Dain Sundstrom Master

                              > Hi dsundstrom,
                              >
                              > You mentioned that mapping of CMR & CMP fields to
                              > same column will be available in JBoss 3.1. If I
                              > checkout today's src code and build that, will I get
                              > that feature. In other words, is it already
                              > implemented.

                              No

                              > How can I checkout JBoss 3.1 HEAD, I have seen it's
                              > references around but could not understand whether it
                              > is a tag or not. So, to get the latest stuff, I
                              > issued the following command,
                              > cvs checkout jboss-all
                              > Do you think I have got the 3.1 HEAD tree.

                              Yep, 3.1 is HEAD right now.

                              > Nonetheless, I have something which I believe is
                              > latest and built JBoss successfully, except for the
                              > catalina which still fails to build. It throws
                              > errors saying,
                              > package javax.servlet does not exist
                              > cannot resolve symbol
                              > [javac]symbol : class XmlAction
                              > I don't know how to define classpath and
                              > local.classpath in build.xml to let Ant know where
                              > the required jar files are.

                              Got me. I don't know anything about Catalina integration. It builds fine for me, so I suggest you update your source again and do a clean build.