2 Replies Latest reply on Aug 12, 2005 5:59 PM by Chris Mc

    CMR field "is not a cmr field". What did I do wrong?

    Chris Mc Newbie

      I have this really really simple and small project with some CMR relationships, but when I try to create a simple EJB-QL query, JBoss says that my CMR field "is not a cmr field". I don't know why, I did everything my books told me. I have my code below, and this is the error it gives me:

      org.jboss.deployment.DeploymentException: Error compiling EJB-QL statement
       'SELECT OBJECT(osp) FROM OptimizationStaticParameter AS osp
       WHERE osp.optimization.name = ?1
       AND osp.optimization.timestamp = ?2
       AND osp.parameterName = ?3'; - nested throwable: (org.jboss.ejb.plugins.cmp.ejbql.UnknownPathException: In path field is not a cmr field: at line 2, column 71. Encountered: "optimization" after: "osp.")


      The CMR relationship is a Unidirectional one-to-many relationship. OptimizationBean contains between 0 and N OptimizationStaticParameterBeans. ("An Optimization contains Static-Parameters")

      Everything is REALLY simple, and it was built from the bottom up. It deploys OK if the EJB-QL queries are removed.
      This seems very simple to me, and everything I have read says I am doing this right. Can someone glance and see what I did wrong? I desperately need this to continue!

      Thanks to anyone!!


      ejb-jar.xml:
      <?xml version="1.0" encoding="UTF-8" ?>
      <ejb-jar
       xmlns="http://java.sun.com/xml/ns/j2ee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
       version="2.1">
       <enterprise-beans>
      
       <entity>
       <ejb-name>OptimizationEJB</ejb-name>
       <local-home>com.flytrading.trading.ejb.OptimizationHomeLocal</local-home>
       <local>com.flytrading.trading.ejb.OptimizationLocal</local>
       <ejb-class>com.flytrading.trading.ejb.OptimizationBean</ejb-class>
       <persistence-type>Container</persistence-type>
       <prim-key-class>java.lang.Object</prim-key-class>
       <reentrant>False</reentrant>
       <abstract-schema-name>Optimization</abstract-schema-name>
       <cmp-field><field-name>name</field-name></cmp-field>
       <cmp-field><field-name>timestamp</field-name></cmp-field>
       <cmp-field><field-name>comment</field-name></cmp-field>
       <security-identity><use-caller-identity/></security-identity>
       </entity>
       <entity>
       <ejb-name>OptimizationStaticParameterEJB</ejb-name>
       <local-home>com.flytrading.trading.ejb.OptimizationStaticParameterHomeLocal</local-home>
       <local>com.flytrading.trading.ejb.OptimizationStaticParameterLocal</local>
       <ejb-class>com.flytrading.trading.ejb.OptimizationStaticParameterBean</ejb-class>
       <persistence-type>Container</persistence-type>
       <prim-key-class>java.lang.Object</prim-key-class>
       <reentrant>False</reentrant>
       <abstract-schema-name>OptimizationStaticParameter</abstract-schema-name>
       <cmp-field><field-name>parameterName</field-name></cmp-field>
       <cmp-field><field-name>value</field-name></cmp-field>
       <cmp-field><field-name>optimization</field-name></cmp-field>
       <security-identity><use-caller-identity/></security-identity>
       <query>
       <query-method>
       <method-name>ejbSelectUnique</method-name>
       <method-params>
       <method-param>java.lang.String</method-param>
       <method-param>java.util.Date</method-param>
       <method-param>java.lang.String</method-param>
       </method-params>
       </query-method>
       <ejb-ql>
       SELECT OBJECT(osp) FROM OptimizationStaticParameter AS osp
       WHERE osp.optimization.name = ?1
       AND osp.optimization.timestamp = ?2
       AND osp.parameterName = ?3
       </ejb-ql>
       </query>
      
       </entity>
       </enterprise-beans>
      
       <relationships>
       <ejb-relation>
       <ejb-relation-name>Optimization-OptStaticParam</ejb-relation-name>
       <ejb-relationship-role>
       <ejb-relationship-role-name>
       Optimization-may-have-StaticParams
       </ejb-relationship-role-name>
       <multiplicity>One</multiplicity>
       <relationship-role-source>
       <ejb-name>OptimizationEJB</ejb-name>
       </relationship-role-source>
       </ejb-relationship-role>
       <ejb-relationship-role>
       <ejb-relationship-role-name>
       OptStaticParam-belongs-to-Optimization
       </ejb-relationship-role-name>
       <multiplicity>Many</multiplicity>
       <relationship-role-source>
       <ejb-name>OptimizationStaticParameterEJB</ejb-name>
       </relationship-role-source>
       <cmr-field>
       <cmr-field-name>optimization</cmr-field-name>
       </cmr-field>
       </ejb-relationship-role>
       </ejb-relation>
      
       </relationships>
      
       <assembly-descriptor>
       <security-role>
       <role-name>everyone</role-name>
       <description>
       This role represents everyone who is allowed full access to the system.
       </description>
       </security-role>
      
       <method-permission>
       <role-name>everyone</role-name>
       <method>
       <ejb-name>OptimizationEJB</ejb-name>
       <method-name>*</method-name>
       </method>
       <method>
       <ejb-name>OptimizationStaticParameterEJB</ejb-name>
       <method-name>*</method-name>
       </method>
       </method-permission>
      
       <container-transaction>
       <method>
       <ejb-name>OptimizationEJB</ejb-name>
       <method-name>*</method-name>
       </method>
       <method>
       <ejb-name>OptimizationStaticParameterEJB</ejb-name>
       <method-name>*</method-name>
       </method>
       <trans-attribute>Required</trans-attribute>
       </container-transaction>
      
       </assembly-descriptor>
      
      </ejb-jar>


      jboss.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd">
      
      <jboss>
       <enterprise-beans>
       <entity>
       <ejb-name>OptimizationEJB</ejb-name>
       <jndi-name>OptimizationHomeRemote</jndi-name>
       <local-jndi-name>OptimizationHomeLocal</local-jndi-name>
       </entity>
      
       <entity>
       <ejb-name>OptimizationStaticParameterEJB</ejb-name>
       <jndi-name>OptimizationStaticParameterHomeRemote</jndi-name>
       <local-jndi-name>OptimizationStaticParameterHomeLocal</local-jndi-name>
       </entity>
       </enterprise-beans>
      
       <resource-managers>
       </resource-managers>
      
      </jboss>


      jbosscmp-jdbc.xml:
      <jbosscmp-jdbc>
       <defaults>
       <unknown-pk>
       <unknown-pk-class>java.lang.Integer</unknown-pk-class>
       <jdbc-type>INTEGER</jdbc-type>
       <sql-type>SERIAL</sql-type>
       <auto-increment/>
       </unknown-pk>
       </defaults>
      
       <entity>
       <ejb-name>OptimizationEJB</ejb-name>
       <cmp-field>
       <field-name>id</field-name>
       <column-name>id</column-name>
       <auto-increment/>
       </cmp-field>
       <entity-command name="postgresql-fetch-seq"/>
       </entity>
       <entity>
       <ejb-name>OptimizationStaticParameterEJB</ejb-name>
       <cmp-field>
       <field-name>id</field-name>
       <column-name>id</column-name>
       <auto-increment/>
       </cmp-field>
       <entity-command name="postgresql-fetch-seq"/>
       </entity>
      
      </jbosscmp-jdbc>


      A reduced version of OptimizationStaticParameterBean.java:
      abstract public class OptimizationStaticParameterBean implements EntityBean {
      
       /*
       ...
       EJB Standard Callback
       ...
       EJB Create / PostCreate Methods
       ...
       */
      
       /*
       * CMP Persistence Fields
       * ---------------------------------------------------------------
       */
      
       abstract public String getParameterName();
       abstract public void setParameterName(String name);
      
       abstract public String getValue();
       abstract public void setValue(String value);
      
       /*
       * CM-Relationship Fields
       * ----------------------------------------------------------------
       */
      
       abstract public OptimizationLocal getOptimization();
       abstract public void setOptimization(OptimizationLocal opt);
      
      
       /*
       * Select methods
       * ----------------------------------------------------------------
       */
      
       abstract public OptimizationStaticParameterLocal ejbSelectUnique(String optName,
       java.util.Date optTimestamp,
       String paramName)
       throws FinderException;
      
      }








        • 1. Re: CMR field
          Stephan Hartmann Newbie

          I think you have to define your relationship also in jbosscmp-jdbc.xml.

          See http://docs.jboss.org/jbossas/jboss4guide/r2/html/ch11.chapter.html#ch11.cmr.sect
          for details.

          Regards,
          Beffe

          • 2. Re: CMR field
            Chris Mc Newbie

            I found the solution.

            Thank you, beffe, for pointing me to the CMP documentation. Actually, the error was not in that part of my code, it was something much simpler and stupider. (The reason my error was stupid is because I wasn't paying full attention when this error first happened. I'm lazy.)

            Unfortunately, O'Reilly's Enterprise JavaBeans is not well organized, and not everything involving CMR is under the CMR chapter, some of it is in Section 6.5. In there, a very subtle thing is implied, but not stated... I'm frustrated with the book.

            The solution is: Even though CMR is part of CMP, you do *not* create a <cmp-field> entry for each <cmr-field> in the section.

            This is my new ejb-jar.xml. Notice the commented-out line in OptimizationStaticParameter:

            <?xml version="1.0" encoding="UTF-8" ?>
            <ejb-jar
             xmlns="http://java.sun.com/xml/ns/j2ee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
             version="2.1">
             <enterprise-beans>
            
             <entity>
             <ejb-name>OptimizationEJB</ejb-name>
             <local-home>com.flytrading.trading.ejb.OptimizationHomeLocal</local-home>
             <local>com.flytrading.trading.ejb.OptimizationLocal</local>
             <ejb-class>com.flytrading.trading.ejb.OptimizationBean</ejb-class>
             <persistence-type>Container</persistence-type>
             <prim-key-class>java.lang.Object</prim-key-class>
             <reentrant>False</reentrant>
             <abstract-schema-name>Optimization</abstract-schema-name>
             <cmp-field><field-name>name</field-name></cmp-field>
             <cmp-field><field-name>timestamp</field-name></cmp-field>
             <cmp-field><field-name>comment</field-name></cmp-field>
             <security-identity><use-caller-identity/></security-identity>
             </entity>
             <entity>
             <ejb-name>OptimizationStaticParameterEJB</ejb-name>
             <local-home>com.flytrading.trading.ejb.OptimizationStaticParameterHomeLocal</local-home>
             <local>com.flytrading.trading.ejb.OptimizationStaticParameterLocal</local>
             <ejb-class>com.flytrading.trading.ejb.OptimizationStaticParameterBean</ejb-class>
             <persistence-type>Container</persistence-type>
             <prim-key-class>java.lang.Object</prim-key-class>
             <reentrant>False</reentrant>
             <abstract-schema-name>OptimizationStaticParameter</abstract-schema-name>
             <cmp-field><field-name>parameterName</field-name></cmp-field>
             <cmp-field><field-name>value</field-name></cmp-field>
            <!-- <cmp-field><field-name>optimization</field-name></cmp-field> -->
             <security-identity><use-caller-identity/></security-identity>
             <query>
             <query-method>
             <method-name>ejbSelectUnique</method-name>
             <method-params>
             <method-param>java.lang.String</method-param>
             <method-param>java.util.Date</method-param>
             <method-param>java.lang.String</method-param>
             </method-params>
             </query-method>
             <ejb-ql>
             SELECT OBJECT(osp) FROM OptimizationStaticParameter AS osp
             WHERE osp.optimization.name = ?1
             AND osp.optimization.timestamp = ?2
             AND osp.parameterName = ?3
             </ejb-ql>
             </query>
            
             </entity>
             </enterprise-beans>
            
             <relationships>
             <ejb-relation>
             <ejb-relation-name>Optimization-OptStaticParam</ejb-relation-name>
             <ejb-relationship-role>
             <ejb-relationship-role-name>
             Optimization-may-have-StaticParams
             </ejb-relationship-role-name>
             <multiplicity>One</multiplicity>
             <relationship-role-source>
             <ejb-name>OptimizationEJB</ejb-name>
             </relationship-role-source>
             </ejb-relationship-role>
             <ejb-relationship-role>
             <ejb-relationship-role-name>
             OptStaticParam-belongs-to-Optimization
             </ejb-relationship-role-name>
             <multiplicity>Many</multiplicity>
             <relationship-role-source>
             <ejb-name>OptimizationStaticParameterEJB</ejb-name>
             </relationship-role-source>
             <cmr-field>
             <cmr-field-name>optimization</cmr-field-name>
             </cmr-field>
             </ejb-relationship-role>
             </ejb-relation>
            
             </relationships>
            
             <assembly-descriptor>
             <security-role>
             <role-name>everyone</role-name>
             <description>
             This role represents everyone who is allowed full access to the system.
             </description>
             </security-role>
            
             <method-permission>
             <role-name>everyone</role-name>
             <method>
             <ejb-name>OptimizationEJB</ejb-name>
             <method-name>*</method-name>
             </method>
             <method>
             <ejb-name>OptimizationStaticParameterEJB</ejb-name>
             <method-name>*</method-name>
             </method>
             </method-permission>
            
             <container-transaction>
             <method>
             <ejb-name>OptimizationEJB</ejb-name>
             <method-name>*</method-name>
             </method>
             <method>
             <ejb-name>OptimizationStaticParameterEJB</ejb-name>
             <method-name>*</method-name>
             </method>
             <trans-attribute>Required</trans-attribute>
             </container-transaction>
            
             </assembly-descriptor>
            
            </ejb-jar>