2 Replies Latest reply on Aug 10, 2005 6:32 PM by Chris Mc

    [AS 4.0.2] EntityBeans & CMR: ejbSelect deploy error: NullPo

    Chris Mc Newbie

      [AS 4.0.2] EntityBeans & CMR: ejbSelect deploy error: NullPointerException in JDBCEJBQLCompiler & metadata

      (this is a continuance of this topic posting: http://www.jboss.com/index.html?module=bb&op=viewtopic&t=67661)

      I'm using JBossAS 4.0.2 and PostgreSQL 8

      I have to get 2 EntityBeans, OptimizationDynamicParameter and OptimizationStaticParameter, to be contained by a third EntityBean, Optimization. Both of the "Parameter" EntityBeans have cmp-fields that reference their containing Optimization. I want an ejbSelect method that takes an Optimization as a method-param in EJB-QL.

      I'm a beginner, so this is a very straightforward application.

      These are the 3 EntityBeans that should work together:

      <entity>
       <ejb-name>OptimizationEJB</ejb-name>
       <home>com.flytrading.trading.ejb.OptimizationHomeRemote</home>
       <remote>com.flytrading.trading.ejb.OptimizationRemote</remote>
       <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>basket</field-name></cmp-field>
       <cmp-field><field-name>parentConfiguration</field-name></cmp-field>
       <cmp-field><field-name>comment</field-name></cmp-field>
       <security-identity><use-caller-identity/></security-identity>
      </entity>
      
      <entity>
       <ejb-name>OptimizationDynamicParameterEJB</ejb-name>
       <local-home>com.flytrading.trading.ejb.OptimizationDynamicParameterHomeLocal</local-home>
       <local>com.flytrading.trading.ejb.OptimizationDynamicParameterLocal</local>
       <ejb-class>com.flytrading.trading.ejb.OptimizationDynamicParameterBean</ejb-class>
       <persistence-type>Container</persistence-type>
       <prim-key-class>java.lang.Object</prim-key-class>
       <reentrant>False</reentrant>
       <abstract-schema-name>OptimizationDynamicParameter</abstract-schema-name>
       <cmp-field><field-name>optimization</field-name></cmp-field>
       <cmp-field><field-name>parameterName</field-name></cmp-field>
       <cmp-field><field-name>startValue</field-name></cmp-field>
       <cmp-field><field-name>stopValue</field-name></cmp-field>
       <cmp-field><field-name>stepSize</field-name></cmp-field>
       <security-identity><use-caller-identity/></security-identity>
       <query>
       <query-method>
       <method-name>ejbSelectTest1</method-name>
       <method-params>
       <method-param>com.flytrading.trading.ejb.OptimizationLocal</method-param>
       </method-params>
       </query-method>
       <ejb-ql>
       SELECT OBJECT(odp) FROM OptimizationDynamicParameter AS odp
       WHERE odp.optimization = ?1
       </ejb-ql>
       </query>
      </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>ejbSelectTest1</method-name>
       <method-params>
       <method-param>com.flytrading.trading.ejb.OptimizationLocal</method-param>
       </method-params>
       </query-method>
       <ejb-ql>
       SELECT OBJECT(osp) FROM OptimizationStaticParameter AS osp
       WHERE osp.optimization = ?1
       </ejb-ql>
       </query>
      </entity>



      As seen in the above code, below are my very simple ejbSelect statements. They just see if an entity bean has a reference to the parameter bean (they've been simplified for demonstration).

      <query>
       <query-method>
       <method-name>ejbSelectTest1</method-name>
       <method-params>
       <method-param>com.flytrading.trading.ejb.OptimizationLocal</method-param>
       </method-params>
       </query-method>
       <ejb-ql>
       SELECT OBJECT(odp) FROM OptimizationDynamicParameter AS odp
       WHERE odp.optimization = ?1
       </ejb-ql>
      </query>


      and

      <query>
       <query-method>
       <method-name>ejbSelectTest1</method-name>
       <method-params>
       <method-param>com.flytrading.trading.ejb.OptimizationLocal</method-param>
       </method-params>
       </query-method>
       <ejb-ql>
       SELECT OBJECT(osp) FROM OptimizationStaticParameter AS osp
       WHERE osp.optimization = ?1
       </ejb-ql>
      </query>



      When all of this is deployed, a NullPointerException occurs in JDBCEJBQLCompiler.verifyParameterEntityType(int number, JDBCEntityBridge entity). Then the NullPointer is caught and then a DeploymentException is thrown

      This is the NullPointerException:
      java.lang.NullPointerException
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLCompiler.verifyParameterEntityType(JDBCEJBQLCompiler.java:338)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLCompiler.compareEntity(JDBCEJBQLCompiler.java:380)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLCompiler.visit(JDBCEJBQLCompiler.java:1369)
       at org.jboss.ejb.plugins.cmp.ejbql.ASTEntityComparison.jjtAccept(ASTEntityComparison.java:23)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLCompiler.visit(JDBCEJBQLCompiler.java:1728)
       at org.jboss.ejb.plugins.cmp.ejbql.ASTWhereConditionalTerm.jjtAccept(ASTWhereConditionalTerm.java:25)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLCompiler.visit(JDBCEJBQLCompiler.java:1056)
       at org.jboss.ejb.plugins.cmp.ejbql.ASTWhere.jjtAccept(ASTWhere.java:23)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLCompiler.visit(JDBCEJBQLCompiler.java:523)
       at org.jboss.ejb.plugins.cmp.ejbql.ASTEJBQL.jjtAccept(ASTEJBQL.java:23)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLCompiler.compileEJBQL(JDBCEJBQLCompiler.java:156)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.<init>(JDBCEJBQLQuery.java:43)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCCommandFactory.createEJBQLQuery(JDBCCommandFactory.java:60)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCQueryManager.start(JDBCQueryManager.java:272)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.startStoreManager(JDBCStoreManager.java:490)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.start(JDBCStoreManager.java:381)
       at org.jboss.ejb.plugins.CMPPersistenceManager.start(CMPPersistenceManager.java:157)
       at org.jboss.ejb.EntityContainer.startService(EntityContainer.java:340)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:272)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:222)
       at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
      
       // ... and more, and more, and so on ...
      



      I've traced the code... it's crashing while parsing the EJB-QL. It attempts to read the EntityBean comparison clause after "WHERE", but it's missing some metadata.

      This is the code it crashes on.

      
      /*
       * This is JBossAS 4.0.2 Code!!
       */
      
      public final class JDBCEJBQLCompiler extends BasicVisitor implements QLCompiler {
      
       // ...
      
       // verify that parameter is the same type as the entity
       private void verifyParameterEntityType(int number,
       JDBCEntityBridge entity)
       {
       Class parameterType = getParameterType(number);
       Class remoteClass = entity.getMetaData().getRemoteClass(); // ### CRASH: NullPointerException
       Class localClass = entity.getMetaData().getLocalClass();
       if((
       localClass == null ||
       !localClass.isAssignableFrom(parameterType)
       ) &&
       (
       remoteClass == null ||
       !remoteClass.isAssignableFrom(parameterType)
       ))
       {
      
       throw new IllegalStateException("Only like types can be " +
       "compared: from entity=" +
       entity.getEntityName() +
       " to parameter type=" + parameterType);
       }
       }
      
       // ...
      
      }
      


      Apparently entity.getMetaData() == null, and the server doesn't expect this.

      Can someone give me a clue as what would cause this problem?


      Thanks for reading this far!
      Please post if you need anything.



        • 1. Re: [AS 4.0.2] EntityBeans & CMR: ejbSelect deploy error: Nu
          Frank Langelage Master

          What's the datatype for the cmp-field optimization ?
          You'll have to use a parameter of the corresponding java type as the parameter for the query.
          But probably you want to use relations here.
          OptimizationDynamicParameter and OptimizationStaticParameter referencing Optimization.
          Then your query's where clause will look like 'odb.optimization.name = ?1"

          • 2. Re: [AS 4.0.2] EntityBeans & CMR: ejbSelect deploy error: Nu
            Chris Mc Newbie

            The datatype for the "optimization" field in OptimizationDynamicParameter and OptimizationStaticParameter is OptimizationLocal

            I am using relations. The relation blocks look like:

            <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>
            <ejb-relation>
             <ejb-relation-name>Optimization-OptDynParam</ejb-relation-name>
             <ejb-relationship-role>
             <ejb-relationship-role-name>
             Optimization-has-DynParams
             </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>
             OptDynParam-belongs-to-Optimization
             </ejb-relationship-role-name>
             <multiplicity>Many</multiplicity>
             <relationship-role-source>
             <ejb-name>OptimizationDynamicParameterEJB</ejb-name>
             </relationship-role-source>
             <cmr-field>
             <cmr-field-name>optimization</cmr-field-name>
             </cmr-field>
             </ejb-relationship-role>
            </ejb-relation>



            All of my EntityBeans have java.lang.Object Primary Keys, because I need JBoss to auto-increment all of my keys so that PostgreSQL will index the table for speed.

            According to O'Reilly's Enterprise JavaBeans, I should be able to use EntityBeans as method-params to EJB-QL queries... so I should not have to worry about primary keys in ejb-jar.xml


            So, I should be able to do EJB-QL like below:
            <query>
             <query-method>
             <method-name>ejbSelectTest1</method-name>
             <method-params>
             <method-param>com.flytrading.trading.ejb.OptimizationLocal</method-param>
             </method-params>
             </query-method>
             <ejb-ql>
             SELECT OBJECT(odp) FROM OptimizationDynamicParameter AS odp
             WHERE odp.optimization = ?1
             </ejb-ql>
            </query>


            and it should compile. At least, everything tells me that should work.


            ...
            Since I have been trying to find different solutions, I have been creating ejbSelect queries that *do not* have EntityBeans as method-params, but the queries do use the optimization field... With solutions like:

            <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>


            I have been getting errors like:

            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 ejb-jar.xml for these entity beans are in my last post). Does anyone know why this is happening? I declared the CMR relationships in the relationships section in ejb-jar.xml, why does it tell me that it is not a CMR field?

            Sorry if this is stupid, but everything says this should work.
            Thanks for reading.

            Chris