3 Replies Latest reply on Aug 6, 2009 3:54 PM by ben_utzer

    EntityQuery NPE

    ben_utzer

      Hi,


      The problems I'm facing are that the order-property of my EntityQuery-subclass is ignored and that I get a NPE at org.hibernate.hql.ast.ParameterTranslationsImpl.getNamedParameterExpectedType(ParameterTranslationsImpl.java:63) for my second restriction (please see below).


      The generated HQL is:


      select person from Person person left join person.gruppen gruppe where lower(person.personentyp.gruppentyp.bezeichnung) = (:el1)) and :el2 in (gruppe.kennung) order by person.id desc


      So everything looks fine to me.


      My EntityQuery is defined as follows in components.xml:




      <framework:entity-query name="mitarbeiterQuery" 
                class="MitarbeiterQuery" max-results="20"
                scope="conversation">
                <property name="ejbql">select person from Person person left join person.gruppen gruppe</property>
                <property name="entityClass">Person</property>
                <framework:order>person.id desc</framework:order>
                <framework:restrictions>
                     <value>lower(person.personentyp.gruppentyp.bezeichnung) =
                          (#{'mitarbeiter'}))</value>
                     <value>#{mitarbeiterQuery.gruppe.kennung} in (gruppe.kennung)
                          </value>                    
                </framework:restrictions>
      </framework:entity-query>



      MitarbeiterQuery.java:




      public class MitarbeiterQuery extends CustomEntityQuery<Person> implements
                Serializable {
           
           @In
           private EntityManager entityManager;
      
           private Gruppe gruppe;
      
           public Gruppe getGruppe() {
                return gruppe;
           }
      
           public void setGruppe(Gruppe gruppe) {
                this.gruppe = gruppe;
           }
      
           @Override
           public void clear() {
                super.clear();
                this.gruppe = new Gruppe();
                ...
           }
      
           public List<Integer> getJahrgaenge() {
                return jahrgaenge;
           }
      
           public void setJahrgaenge(List<Integer> jahrgaenge) {
                this.jahrgaenge = jahrgaenge;
           }
      
           @Factory(value = "jahrgaenge")
           public void loadJahrgaenge() {
                this.jahrgaenge = entityManager.createNamedQuery("jahrgaenge")
                          .getResultList();
           }
              ...
      }
      



      I would appreciate any help on how to get this working.


      Thanks in advancee,


      Ben

        • 1. Re: EntityQuery NPE
          lvdberg

          Ben,


          make sure gruppe never is NULL, because that will lead to a hibernate crash. Add a null check in your EL in the restriction.


          Leo

          • 2. Re: EntityQuery NPE
            ben_utzer

            Hi Leo, thanks for your reply.


            #{mitarbeiterQuery.gruppe} is never null. I also successfully executed the HQL-statement with Person-objects which did have an empty gruppen-property.
            The problem must be somewhere else.


            The order clause-problem does not relate to the NPE, it does not work even if I remove the gruppen-restriction.


            Here's the complete stacktrace:




            java.lang.NullPointerException
                 at org.hibernate.hql.ast.ParameterTranslationsImpl.getNamedParameterExpectedType(ParameterTranslationsImpl.java:63)
                 at org.hibernate.engine.query.HQLQueryPlan.buildParameterMetadata(HQLQueryPlan.java:296)
                 at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:97)
                 at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
                 at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
                 at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
                 at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
                 at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
                 at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:93)
                 at org.jboss.seam.persistence.EntityManagerProxy.createQuery(EntityManagerProxy.java:81)
                 at org.jboss.seam.framework.EntityQuery.createQuery(EntityQuery.java:181)
                 at org.jboss.seam.framework.EntityQuery.initResultList(EntityQuery.java:79)
                 at org.jboss.seam.framework.EntityQuery.getResultList(EntityQuery.java:71)
                 at sun.reflect.GeneratedMethodAccessor128.invoke(Unknown Source)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:597)
                 at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
                 at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                 at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                 at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                 at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:97)
                 at org.jboss.seam.util.Work.workInTransaction(Work.java:47)
                 at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                 at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                 at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                 at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
                 at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
                 at de.beracom.vplan5.service.MitarbeiterQuery_$$_javassist_seam_4.getResultList(MitarbeiterQuery_$$_javassist_seam_4.java)
            ...
            





            Regards,


            Ben

            • 3. Re: EntityQuery NPE
              ben_utzer

              Ok, I finally found the problem - a non-matched parentheses... doh!


              lower(person.personentyp.gruppentyp.bezeichnung) =
                                  (#{'mitarbeiter'}) --> ) <-- evil