3 Replies Latest reply on Nov 12, 2007 12:55 PM by Pete Muir

    EntityQuery restriction help

    Daniel Löbbe Newbie

      Hi all,
      after searching the examples, documentation and forum for a solution I can't get the following use case to work:
      I like to restrict the EntityQuery for object A by a related Object B. The Entities and search-dialogue are created by seam-gen. But I like to add a simple single select list of object of class b as search criteria.

      My code:

      @Entity
      public class A implements Serializable
      {
       @Id
       @GeneratedValue(strategy = GenerationType.AUTO)
       private Long id;
      
       @ManyToOne(fetch = FetchType.EAGER)
       @JoinColumn(name = "bid", nullable = true)
       private B b;
      }
      
      @Entity
      public class B implements Serializable
      {
       @Id
       @GeneratedValue(strategy = GenerationType.AUTO)
       private Long id;
      
       @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "b")
       private Set<A> as;
      }
      


      I like to create an EntityQuery, which searches / returns Objects of class A related to a specific Object of class B. One of my tries looks as follows:
      @Name("aList")
      public class AList extends EntityQuery
      {
       private static final String[] RESTRICTIONS = {
       "b = #{aList.a.b}", };
      
       @Override
       public String getEjbql()
       {
       return "select a from A as a join a.b as b";
       }
      }
      

      Which produces an error like:
      Caused by: java.lang.IllegalArgumentException: argument type mismatch
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at javax.el.BeanELResolver.setValue(BeanELResolver.java:108)
       ... 58 more
      



      Another one like this:
      @Name("aList")
      public class AList extends EntityQuery
      {
       private static final String[] RESTRICTIONS = {
       "a.b = #{aList.a.b}", };
      
       @Override
       public String getEjbql()
       {
       return "select a from A as a";
       }
      }
      

      Resolves in the same. In both cases, the query parameter is set properly to an object of class B.


      What am I doing wrong? Or can just someone provide an example on how to restrict EntityQueries by @ManyToOne-related Entities?

      Thanks for help,

      Daniel

        • 1. Re: EntityQuery restriction help
          Pete Muir Master

          Post the WHOLE stack trace

          • 2. Re: EntityQuery restriction help
            Daniel Löbbe Newbie

             

            16:35:00,307 ERROR [SeamPhaseListener] uncaught exception
            javax.el.ELException: java.lang.IllegalArgumentException: argument type mismatch
             at javax.el.BeanELResolver.setValue(BeanELResolver.java:116)
             at javax.el.CompositeELResolver.setValue(CompositeELResolver.java:68)
             at com.sun.faces.el.FacesCompositeELResolver.setValue(FacesCompositeELResolver.java:93)
             at org.jboss.el.parser.AstPropertySuffix.setValue(AstPropertySuffix.java:73)
             at org.jboss.el.parser.AstValue.setValue(AstValue.java:84)
             at org.jboss.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:249)
             at org.jboss.seam.core.Expressions$1.setValue(Expressions.java:117)
             at org.jboss.seam.navigation.Pages.applyConvertedValidatedValuesToModel(Pages.java:779)
             at org.jboss.seam.navigation.Pages.postRestore(Pages.java:402)
             at org.jboss.seam.jsf.SeamPhaseListener.postRestorePage(SeamPhaseListener.java:528)
             at org.jboss.seam.jsf.SeamPhaseListener.afterRestoreView(SeamPhaseListener.java:374)
             at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:211)
             at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:184)
             at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:280)
             at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
             at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
             at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:164)
             at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:141)
             at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:90)
             at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:406)
             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.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:44)
             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.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
             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.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
             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:230)
             at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
             at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
             at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
             at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
             at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
             at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
             at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
             at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
             at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
             at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
             at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
             at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
             at java.lang.Thread.run(Thread.java:619)
            Caused by: java.lang.IllegalArgumentException: argument type mismatch
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:597)
             at javax.el.BeanELResolver.setValue(BeanELResolver.java:108)
             ... 58 more
            16:35:00,339 ERROR [CachedConnectionValve] Application error: Faces Servlet did not complete its transaction
            


            That is all.

            Thanks, Daniel

            • 3. Re: EntityQuery restriction help
              Pete Muir Master

              Nothing to do with the query, you have a problem applying the page parameters for the page to the model