8 Replies Latest reply on May 17, 2004 8:50 AM by homer

    NullPointerException compiling EJB-QL

    homer

      Hi,

      I have a problem compiling EJB-QL when trying deploy my beans. Can anyone help me ?
      I don't understand what's wrong with my EJB-QL !

      Thanks

      My xdoclet :

      * @ejb.finder signature = "fr.edumedia.interfaces.entity.catalogue.ContainingFamillyLocal findByAnimationAndFamilly(fr.edumedia.interfaces.entity.catalogue.AnimationLocal animation, fr.edumedia.interfaces.entity.catalogue.FamillyLocal familly)"
      * query = "SELECT OBJECT(c)
      * FROM ContainingFamilly AS c
      * WHERE c.animation = ?1 AND c.family = ?2"

      The exception throwed :

      org.jboss.deployment.DeploymentException: Error compiling EJB-QL statement 'SELECT OBJECT(c) FROM ContainingFamilly AS c WHERE c.animation = ?1 AND c.family = ?2'; - nested throwable: (java.lang.NullPointerException)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.(JDBCEJBQLQuery.java:50)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCCommandFactory.createEJBQLQuery(JDBCCommandFactory.java:59)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCQueryManager.start(JDBCQueryManager.java:212)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.startStoreManager(JDBCStoreManager.java:490)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.start(JDBCStoreManager.java:388)
      at org.jboss.ejb.plugins.CMPPersistenceManager.start(CMPPersistenceManager.java:152)
      at org.jboss.ejb.EntityContainer.startService(EntityContainer.java:342)
      at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:192)
      at sun.reflect.GeneratedMethodAccessor438.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
      at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:976)
      at $Proxy14.start(Unknown Source)
      at org.jboss.system.ServiceController.start(ServiceController.java:394)
      at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
      at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
      at $Proxy2562.start(Unknown Source)
      at org.jboss.ejb.EjbModule.startService(EjbModule.java:331)
      at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:192)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
      at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:976)
      at $Proxy14.start(Unknown Source)
      at org.jboss.system.ServiceController.start(ServiceController.java:394)
      at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
      at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
      at $Proxy12.start(Unknown Source)
      at org.jboss.ejb.EJBDeployer.start(EJBDeployer.java:544)
      at org.jboss.deployment.MainDeployer.start(MainDeployer.java:832)
      at org.jboss.deployment.MainDeployer.start(MainDeployer.java:824)
      at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:642)
      at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:605)
      at sun.reflect.GeneratedMethodAccessor42.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
      at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
      at $Proxy6.deploy(Unknown Source)
      at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:302)
      at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:458)
      at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:201)
      at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:212)
      at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:191)
      Caused by: java.lang.NullPointerException
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLCompiler.verifyParameterEntityType(JDBCEJBQLCompiler.java:323)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLCompiler.compareEntity(JDBCEJBQLCompiler.java:360)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLCompiler.visit(JDBCEJBQLCompiler.java:1238)
      at org.jboss.ejb.plugins.cmp.ejbql.ASTEntityComparison.jjtAccept(ASTEntityComparison.java:23)
      at org.jboss.ejb.plugins.cmp.ejbql.BasicVisitor.visit(BasicVisitor.java:115)
      at org.jboss.ejb.plugins.cmp.ejbql.ASTAnd.jjtAccept(ASTAnd.java:23)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLCompiler.visit(JDBCEJBQLCompiler.java:1526)
      at org.jboss.ejb.plugins.cmp.ejbql.ASTWhereConditionalTerm.jjtAccept(ASTWhereConditionalTerm.java:25)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLCompiler.visit(JDBCEJBQLCompiler.java:958)
      at org.jboss.ejb.plugins.cmp.ejbql.ASTWhere.jjtAccept(ASTWhere.java:23)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLCompiler.visit(JDBCEJBQLCompiler.java:500)
      at org.jboss.ejb.plugins.cmp.ejbql.ASTEJBQL.jjtAccept(ASTEJBQL.java:23)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLCompiler.compileEJBQL(JDBCEJBQLCompiler.java:148)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.(JDBCEJBQLQuery.java:42)
      ... 57 more

        • 1. Re: NullPointerException compiling EJB-QL
          sesques

          Hi,

          Post your code and/or descritors.
          How are declared the cmr fields animation and family ?

          Pascal

          • 2. Re: NullPointerException compiling EJB-QL
            homer

            Ho, sorry !!!

            Thanks for your reply!

            I hope that you will can help me!

            Thanks

            -------------------------------------------------

            The ContainingFamily code :

            * @ejb.bean cmp-version = "2.x"
            * name = "ContainingFamily"
            * primkey-field = "id"
            * view-type = "local"
            * type = "CMP"
            *
            * @ejb.persistence table-name = "containingfamily"
            *
            * @jboss.persistence create-table = "true"
            * pk-constraint = "no"
            * table-name = "containingfamily"
            *
            * @ejb.ejb-ref ejb-name = "Animation"
            * view-type = "local"
            * @ejb.ejb-ref ejb-name = "Family"
            * view-type = "local"
            * @ejb.ejb-ref ejb-name = "Status"
            * view-type = "local"

            *
            * @ejb.util generate = "logical"
            *
            * @ejb.finder signature = "fr.edumedia.interfaces.entity.catalogue.ContainingFamilyLocal findByAnimationAndFamily(fr.edumedia.interfaces.entity.catalogue.AnimationLocal animation, fr.edumedia.interfaces.entity.catalogue.FamilyLocal family)"
            * query = "SELECT OBJECT(c)
            * FROM ContainingFamily AS c
            * WHERE c.animation = ?1 AND c.family = ?2"
            */
            public abstract class ContainingFamilyBean implements EntityBean {

            private EntityContext _ctx;

            //###########################

            /**
            * @ejb.interface-method
            *
            * @ejb.persistence column-name = "id"
            * @jboss.persistence auto-increment = "true"
            * not-null = "true"
            */
            public abstract Integer getId();
            /**
            * @ejb.interface-method
            */
            public abstract void setId(Integer id);

            /**
            * @ejb.interface-method
            *
            * @ejb.persistence column-name = "familyid"
            * jdbc-type = "INTEGER"
            * sql-type = "INTEGER"
            * @jboss.persistence not-null = "true"
            * @ejb.relation name = "ContainingFamily-Family"
            * role-name = "ContainingFamily-of-Family"
            * target-ejb = "Family"
            * target-multiple = "true"
            * cascade-delete = "true"
            * target-role-name = "Family-of-ContainingFamily"
            * @jboss.relation fk-column = "fammilyid"
            * related-pk-field = "id"
            * fk-constraint = "true"
            */
            public abstract FamilyLocal getFamily();
            /**
            * @ejb.interface-method
            */
            public abstract void setFamily(FamilyLocal newContainingFamily);

            /**
            * @ejb.interface-method
            *
            * @ejb.persistence column-name = "animationid"
            * jdbc-type = "INTEGER"
            * sql-type = "INTEGER"
            * @jboss.persistence not-null = "true"
            * @ejb.relation name = "ContainingFamily-Animation"
            * role-name = "ContainingFamily-has-Animation"
            * target-ejb = "Animation"
            * target-multiple = "true"
            * target-role-name = "Animation-In-ContainingFamily"
            * @jboss.relation fk-column = "animationid"
            * related-pk-field = "id"
            * fk-constraint = "true"
            */
            public abstract AnimationLocal getAnimation();
            /**
            * @ejb.interface-method
            */
            public abstract void setAnimation(AnimationLocal newContainedAnimation);
            ...

            ------------------------------------------

            My autogenerated ejb-jar.xml :

            <![CDATA[Permet de g&eacute;rer le contenu des familles et le fait que les animations se trouvent dans un catalogue de production et un (plusieurs) catalogue(s) client(s)]]

            <ejb-name>ContainingFamily</ejb-name>

            <local-home>fr.edumedia.interfaces.entity.catalogue.ContainingFamilyLocalHome</local-home>
            fr.edumedia.interfaces.entity.catalogue.ContainingFamilyLocal

            <ejb-class>fr.edumedia.ejb.entity.catalogue.ContainingFamilyBean</ejb-class>
            <persistence-type>Container</persistence-type>
            <prim-key-class>java.lang.Integer</prim-key-class>
            False
            <cmp-version>2.x</cmp-version>
            <abstract-schema-name>ContainingFamily</abstract-schema-name>
            <cmp-field >
            [CDATA[]]
            <field-name>id</field-name>
            </cmp-field>
            <cmp-field >
            [CDATA[]]
            <field-name>family</field-name>
            </cmp-field>
            <cmp-field >
            [CDATA[]]
            <field-name>animation</field-name>
            </cmp-field>
            <cmp-field >
            [CDATA[]]
            <field-name>position</field-name>
            </cmp-field>
            <primkey-field>id</primkey-field>

            <ejb-local-ref >
            <ejb-ref-name>ejb/Animation</ejb-ref-name>
            <ejb-ref-type>Entity</ejb-ref-type>
            <local-home>fr.edumedia.interfaces.entity.catalogue.AnimationLocalHome</local-home>
            fr.edumedia.interfaces.entity.catalogue.AnimationLocal
            <ejb-link>Animation</ejb-link>
            </ejb-local-ref>
            <ejb-local-ref >
            <ejb-ref-name>ejb/Family</ejb-ref-name>
            <ejb-ref-type>Entity</ejb-ref-type>
            <local-home>fr.edumedia.interfaces.entity.catalogue.FamilyLocalHome</local-home>
            fr.edumedia.interfaces.entity.catalogue.FamilyLocal
            <ejb-link>Family</ejb-link>
            </ejb-local-ref>
            <ejb-local-ref >
            <ejb-ref-name>ejb/Status</ejb-ref-name>
            <ejb-ref-type>Entity</ejb-ref-type>
            <local-home>fr.edumedia.interfaces.entity.parameter.StatusLocalHome</local-home>
            fr.edumedia.interfaces.entity.parameter.StatusLocal
            <ejb-link>Status</ejb-link>
            </ejb-local-ref>


            <query-method>
            <method-name>findByAnimationAndFamily</method-name>
            <method-params>
            <method-param>fr.edumedia.interfaces.entity.catalogue.AnimationLocal</method-param>
            <method-param>fr.edumedia.interfaces.entity.catalogue.FamilyLocal</method-param>
            </method-params>
            </query-method>
            <ejb-ql>[CDATA[SELECT OBJECT(c) FROM ContainingFamily AS c WHERE c.animation = ?1 AND c.family = ?2]]</ejb-ql>

            <!-- Write a file named ejb-finders-ContainingFamilyBean.xml if you want to define extra finders. -->

            ....

            <ejb-relation >
            <ejb-relation-name>ContainingFamily-Animation</ejb-relation-name>

            <ejb-relationship-role >
            <ejb-relationship-role-name>ContainingFamily-has-Animation</ejb-relationship-role-name>
            Many
            <relationship-role-source >
            <ejb-name>ContainingFamily</ejb-name>
            </relationship-role-source>
            <cmr-field >
            <cmr-field-name>animation</cmr-field-name>
            </cmr-field>
            </ejb-relationship-role>

            <ejb-relationship-role >
            <ejb-relationship-role-name>Animation-In-ContainingFamily</ejb-relationship-role-name>
            One
            <relationship-role-source >
            <ejb-name>Animation</ejb-name>
            </relationship-role-source>
            </ejb-relationship-role>

            </ejb-relation>

            ....

            <ejb-relation >
            <ejb-relation-name>ContainingFamily-Family</ejb-relation-name>

            <ejb-relationship-role >
            <ejb-relationship-role-name>ContainingFamily-of-Family</ejb-relationship-role-name>
            Many
            <cascade-delete/>
            <relationship-role-source >
            <ejb-name>ContainingFamily</ejb-name>
            </relationship-role-source>
            <cmr-field >
            <cmr-field-name>family</cmr-field-name>
            </cmr-field>
            </ejb-relationship-role>

            <ejb-relationship-role >
            <ejb-relationship-role-name>Family-of-ContainingFamily</ejb-relationship-role-name>
            One
            <relationship-role-source >
            <ejb-name>Family</ejb-name>
            </relationship-role-source>
            </ejb-relationship-role>

            </ejb-relation>

            • 3. Re: NullPointerException compiling EJB-QL
              sesques

              Hi,

              Your EJB-QL query must refer to the bean, not the table in the FROM clause.
              So it should be:

              * @ejb.finder signature = "fr.edumedia.interfaces.entity.catalogue.ContainingFamilyLocal findByAnimationAndFamily(fr.edumedia.interfaces.entity.catalogue.AnimationLocal animation, fr.edumedia.interfaces.entity.catalogue.FamilyLocal family)"
              * query = "SELECT OBJECT(c)
              * FROM ContainingFamilyBean AS c
              * WHERE c.animation = ?1 AND c.family = ?2"
              */
              


              Pascal




              • 4. Re: NullPointerException compiling EJB-QL
                homer

                Hi,

                Your EJB-QL query must refer to the bean, not the table in the FROM clause.


                In the FROM clause, ContainingFamily is not the table name but the <abstract-schema-name> content in the ejb-jar descriptor.

                * @ejb.finder signature = "fr.edumedia.interfaces.entity.catalogue.ContainingFamilyLocal findByAnimationAndFamily(fr.edumedia.interfaces.entity.catalogue.AnimationLocal animation, fr.edumedia.interfaces.entity.catalogue.FamilyLocal family)" * query = "SELECT OBJECT(c)
                * FROM
                ContainingFamilyBean
                AS c
                * WHERE c.animation = ?1 AND c.family = ?2" */


                To avoid any conflict between the bean names and the table names, I have added "Bean" to all the bean names. But I get the NullPointerException in the two cases. I don't understand why!

                Am I the only one having this problem ?

                It's very important , I have lost one week with this problem!

                Thanks!

                • 5. Re: NullPointerException compiling EJB-QL
                  gorano

                  I think this is what you are looking for:

                  query = "SELECT OBJECT(c) FROM ContainingFamilly AS c, IN (c.Animations) AS ca, IN (c.Families) AS cf WHERE ca = ?1 AND cf = ?2"

                  (I dont know the name of your cmr getters, so change where appropriate)

                  /Goran

                  • 6. Re: NullPointerException compiling EJB-QL
                    homer

                    Hi Goran,

                    I think this is what you are looking for:

                    query = "SELECT OBJECT(c) FROM ContainingFamilly AS c, IN (c.Animations) AS ca, IN (c.Families) AS cf WHERE ca = ?1 AND cf = ?2"


                    Thanks for your reply, but the "animation" and "family" fields in my ContainingFamilly bean are not collections. The IN clause is used to work with collections.

                    i begin to despair! HELP ME PLEASE!!!

                    • 7. Re: NullPointerException compiling EJB-QL
                      sesques

                      Hi,

                      Sorry for my previous response. I looked too quickly at your descriptors.
                      I think the problem is that you have a cmp field named "family" in your ejb-jar.xml descriptor, in addition to CMR fields "family" and "animation".

                      I think this parasitic fiels is generated by the
                      * @ejb.persistence column-name = "familyid"
                      * jdbc-type = "INTEGER"
                      * sql-type = "INTEGER"
                      sequence before the relation definition.

                      I think you don't need theses extra_tags, the column type of the foreign key is setted according to the "Family" bean primary key definition.

                      Pascal

                      • 8. Re: NullPointerException compiling EJB-QL
                        homer

                        Ouchh!!!

                        Incredible, your are GREAT !!!!

                        It was well this problem : erasing this line in all my code, correcting some other minor problems and the deployment works well.

                        Thanks, thanks, thanks !!!!