2 Replies Latest reply on Feb 12, 2008 5:49 PM by Scott Olcott

    How to use in (#{exampleList}) in HibernateEntityQuery

    Scott Olcott Newbie

      Is it possible to use the in statement in an EntityQuery restriction. I am trying to do something like the following:

      <framework:hibernate-entity-query name="testList"
       ejbql="select test from Test test" >
       <framework:restrictions>
       <value>test.name in #{exampleNameList}</value>
       </framework:restrictions>
       </framework:hibernate-entity-query>
      


      However when I try to do this I get an error with the following cause:
      Caused by java.lang.ClassCastException with message: "java.util.ArrayList"
      


      The same happens when I extend HibernateEntityQuery. Has any one else been able to figure out how to do this? Or, does anyone know if it is even possible?

        • 1. Re: How to use in (#{exampleList}) in HibernateEntityQuery
          Pete Muir Master

          Please post the full trace

          • 2. Re: How to use in (#{exampleList}) in HibernateEntityQuery
            Scott Olcott Newbie

            Sorry the ClassCastException was from a custom hibernate type. Here are the real errors I am getting

            Here is the ejbql

            select tempUser from User tempUser


            Here is the restriction
            tempUser.role in (#{exampleRoles})


            Here is the exception
            org.hibernate.PropertyAccessException: could not get a field value by reflection getter of testpackage.Role.id
             at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:35)
             at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:183)
             at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3591)
             at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3307)
             at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
             at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:218)
             at org.hibernate.type.EntityType.getIdentifier(EntityType.java:397)
             at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:87)
             at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:38)
             at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:491)
             at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1563)
             at org.hibernate.loader.Loader.doQuery(Loader.java:673)
             at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
             at org.hibernate.loader.Loader.doList(Loader.java:2220)
             at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
             at org.hibernate.loader.Loader.list(Loader.java:2099)
             at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
             at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
             at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
             at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
             at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
             at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:811)
             at org.jboss.seam.framework.HibernateEntityQuery.initResultCount(HibernateEntityQuery.java:104)
             at org.jboss.seam.framework.HibernateEntityQuery.getResultCount(HibernateEntityQuery.java:95)
             at org.jboss.seam.trinidad.SeamCollectionModel.getRowCount(SeamCollectionModel.java:47)
             at org.apache.myfaces.trinidad.component.UIXCollection.getRowCount(UIXCollection.java:337)
             at org.apache.myfaces.trinidad.model.ModelUtils.findLastIndex(ModelUtils.java:130)
             at org.apache.myfaces.trinidad.component.TableUtils.getLast(TableUtils.java:83)
             at org.apache.myfaces.trinidad.component.TableUtils.getLast(TableUtils.java:57)
             at org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.table.TableUtils.getVisibleRowCount(TableUtils.java:142)
             at org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.table.RowData.<init>(RowData.java:34)
             at org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.table.TableRenderingContext.<init>(TableRenderingContext.java:68)
             at org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TableRenderer.createRenderingContext(TableRenderer.java:408)
             at org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.TableRenderer.encodeAll(TableRenderer.java:253)
             at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:220)
             at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:749)
             at org.apache.myfaces.trinidad.component.UIXCollection.encodeEnd(UIXCollection.java:527)
             at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:286)
             at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
             at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:284)
             at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:143)
             at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:86)
             at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:134)
             at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:86)
             at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:134)
             at org.ajax4jsf.renderkit.AjaxContainerRenderer.encodeAjax(AjaxContainerRenderer.java:122)
             at org.ajax4jsf.component.AjaxViewRoot.encodeAjax(AjaxViewRoot.java:553)
             at org.ajax4jsf.component.AjaxViewRoot$4.invokeRoot(AjaxViewRoot.java:384)
             at org.ajax4jsf.context.JsfOneOneInvoker.invokeOnRegionOrRoot(JsfOneOneInvoker.java:56)
             at org.ajax4jsf.context.AjaxContextImpl.invokeOnRegionOrRoot(AjaxContextImpl.java:170)
             at org.ajax4jsf.component.AjaxViewRoot.encodeChildren(AjaxViewRoot.java:401)
             at javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
             at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
             at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:189)
             at org.apache.myfaces.trinidadinternal.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:175)
             at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
             at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
             at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
             at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
             at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
             at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
             at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._invokeDoFilter(TrinidadFilterImpl.java:241)
             at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:198)
             at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:141)
             at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
             at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
             at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
             at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
             at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
             at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
             at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
             at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
             at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
             at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
             at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
             at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
             at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
             at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
             at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
             at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
             at java.lang.Thread.run(Thread.java:595)
            Caused by: java.lang.IllegalArgumentException
             at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
             at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:18)
             at java.lang.reflect.Field.get(Field.java:357)
             at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:32)
             ... 97 more