6 Replies Latest reply on Jun 19, 2008 4:12 PM by Tiago Sudeval

    Restriction in EntityQuery (argument type mismatch)

    Tiago Sudeval Newbie

      Hi,
      Why my entityList throws an argument type mismatch when i use an not primitive type like param ?


      for example:


      entityList.java
      private static final String[] RESTRICTIONS = {
                      "lower(projeto.titulo) like concat(lower(#{projetoList.projeto.titulo}),'%') ",
                      "projeto.unidadeOperacional.id = (#{projetoList.projeto.unidadeOperacional.id}) ",
                      "projeto.enquadramentoProjeto.programa.id = (#{projetoList.projeto.enquadramentoProjeto.programa.id}) ",                
                      "projeto.statusProjeto.id = (#{projetoList.projeto.statusProjeto.id}) ",
                      "projeto.dataPrevisaoInicio = (#{projetoList.projeto.dataPrevisaoInicio}) "
                      };
      
      
      public List<String> getRestrictions() {           
                      System.out.println("Estado "+projeto.getStatusProjeto());               
                      return Arrays.asList(RESTRICTIONS);
              }
      




      entityList.page.xml
      
      <?xml version="1.0" encoding="UTF-8"?>
      <page xmlns="http://jboss.com/products/seam/pages"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.0.xsd">
      
         <param name="firstResult" value="#{projetoList.firstResult}"/>
         <param name="order" value="#{projetoList.order}"/>
         <param name="from"/>
         <param name="statusProjeto" value="#{projetoList.projeto.statusProjeto}"/>
         <param name="enquadramentoProjeto.programa.id" value="#{projetoList.projeto.enquadramentoProjeto.programa.id}"/>
         <param name="unidadeOperacional.id" value="#{projetoList.projeto.unidadeOperacional.id}"/>
         <param name="dataPrevisaoInicio" value="#{projetoList.projeto.dataPrevisaoInicio}"/>
         <param name="dataPrevisaoFim" value="#{projetoList.projeto.dataPrevisaoFim}" converterId="org.jboss.seam.ui.DateTimeConverter"/>
         <param name="titulo" value="#{projetoList.projeto.titulo}"/>   
      </page>
      




      entityList.xhtml
      <h:form id="formBuscaProjeto" styleClass="edit">
                      <rich:simpleTogglePanel label="Parâmetros da Busca" switchType="ajax">
                              <s:decorate template="layout/display.xhtml">
                                      <ui:define name="label">Título:</ui:define>
                                      <h:inputText id="tituloProjetoParam" value="#{projetoList.projeto.titulo}"/>
                              </s:decorate>
                              <s:decorate template="layout/display.xhtml">
                                      <ui:define name="label">Unidade Operacional:</ui:define>
                                      <h:selectOneMenu value="#{projetoList.projeto.unidadeOperacional}">
                                              <s:selectItems var="unidadeOperacional" 
                                                                       value="#{unidadeOperacionalList.resultList}" 
                                                                       label="#{unidadeOperacional.nome}"
                                                                       noSelectionLabel="selecione uma unidade operacional..."/>
                                              <s:convertEntity/>
                                      </h:selectOneMenu>
                              </s:decorate>
                              <s:decorate template="layout/display.xhtml">
                                      <ui:define name="label">Programa:</ui:define>                                                       
                              </s:decorate>
                              <s:decorate template="layout/display.xhtml">
                                      <ui:define name="label">Categoria:</ui:define>
                              </s:decorate>
                              <s:decorate template="layout/display.xhtml">
                                      <ui:define name="label">Valor:</ui:define>                          
                              </s:decorate>
                              <s:decorate template="layout/display.xhtml">
                                      <ui:define name="label">Período Execução:</ui:define>
                                      <h:inputText value="#{projetoList.projeto.dataPrevisaoInicio}">
                                              <f:convertDateTime type="date" pattern="dd/MM/yyyy"/>
                                      </h:inputText>
                              </s:decorate>
                              <s:decorate template="layout/display.xhtml">
                                      <ui:define name="label">Status:</ui:define>
                                      <h:selectOneMenu value="#{projetoList.projeto.statusProjeto}">
                                              <s:selectItems var="statusProjeto"
                                                                       value="#{statusProjetoList.resultList}" 
                                                                       label="#{statusProjeto.nome}"
                                                                       noSelectionLabel="selecione um status..."/>
                                              <s:convertEntity/>
                                      </h:selectOneMenu>                                
                              </s:decorate>                                     
                      </rich:simpleTogglePanel>
                      
                      <div class="actionButtons">
                  <h:commandButton id="buscar" value="Buscar" action="/projetoList.xhtml"/>
              </div>
      



      error
      ...
      09:45:21,938 INFO  [STDOUT] Estado FINALIZADO
      09:45:21,954 INFO  [STDOUT] Hibernate: 
          select
              top 5 projeto0_.id as id15_,
              projeto0_.titulo as titulo15_,
              projeto0_.justificativa as justific3_15_,
              projeto0_.metodologia as metodolo4_15_,
              projeto0_.objetivoGeral as objetivo5_15_,
              projeto0_.publicoAlvo as publicoA6_15_,
              projeto0_.resultadoDesejado as resultad7_15_,
              projeto0_.dataPrevisaoInicio as dataPrev8_15_,
              projeto0_.dataPrevisaoFim as dataPrev9_15_,
              projeto0_.idUsuario as idUsuario15_,
              projeto0_.idUnidadeOperacional as idUnida13_15_,
              projeto0_.totalRecursosProjeto as totalRe10_15_,
              projeto0_.idEnquadramentoProjeto as idEnqua12_15_,
              projeto0_.idStatus as idStatus15_ 
          from
              Projeto projeto0_ 
          where
              projeto0_.idStatus=?
      09:45:22,032 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:116)
           at org.jboss.seam.navigation.Pages.applyConvertedValidatedValuesToModel(Pages.java:788)
           at org.jboss.seam.navigation.Pages.postRestore(Pages.java:409)
           at org.jboss.seam.jsf.SeamPhaseListener.postRestorePage(SeamPhaseListener.java:544)
           at org.jboss.seam.jsf.SeamPhaseListener.afterRestoreView(SeamPhaseListener.java:390)
           at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:226)
           at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:192)
           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.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:45)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:147)
           at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:256)
           at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:362)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:488)
           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)
           ... 54 more
      






        • 2. Re: Restriction in EntityQuery (argument type mismatch)
          Dan Allen Master

          This problem has nothing to do with the JPQL at all. JSF is not able to assign one of your request parameters to one of the properties on your model. You need two things:


          1) You may need a converter if the property is not a basic type (Seam has a built-in set of converters that it handles, such as String -> Long)


          2) You need to be sure that the target property is accessible through the EL path expression. It may be that the reference to the entity projeto is null, and therefore the target property is not reachable.

          • 3. Re: Restriction in EntityQuery (argument type mismatch)
            Tiago Sudeval Newbie

            hi,
            i resolved with a converter and modifying my entityList.page.xml.



            <param name="firstResult" value="#{projetoList.firstResult}"/>
             <param name="order" value="#{projetoList.order}"/>
             <param name="from"/>
             <param name="titulo" value="#{projetoList.projeto.titulo}"/>
             <param name="statusProjeto" value="#{projetoList.projeto.statusProjeto}" converterId="StatusProjetoConverter"/> 
             <param name="unidadeOperacional" value="#{projetoList.projeto.unidadeOperacional}" converterId="UnidadeOperacionalConverter"/>
            programa.id}"/>
            ...
            
            



            thanks :D


            an another problem is...
            how i do to use a paramater that in a collection..
            for example:


            @Entity
            Company {
              List<Employee> employees;
            }
            
            




            is correct?
            
            <param name="employees"  values="#{companyList.company.employess}"/>
            

            • 4. Re: Restriction in EntityQuery (argument type mismatch)
              Tiago Sudeval Newbie

              a another example: ( and a problem :( )



              my EntityList.class
              ...
              
              private static final String[] RESTRICTIONS = {
                              "projeto.categorias = (#{projetoList.projeto.categorias}) "
              


              this is correct?


               select
                      top 5 projeto0_.id as id134_,
                      projeto0_.titulo as titulo134_,
                      projeto0_.justificativa as justific3_134_,
                      projeto0_.metodologia as metodolo4_134_,
                      projeto0_.objetivoGeral as objetivo5_134_,
                      projeto0_.publicoAlvo as publicoA6_134_,
                      projeto0_.resultadoDesejado as resultad7_134_,
                      projeto0_.dataPrevisaoInicio as dataPrev8_134_,
                      projeto0_.dataPrevisaoFim as dataPrev9_134_,
                      projeto0_.idUsuario as idUsuario134_,
                      projeto0_.idUnidadeOperacional as idUnida14_134_,
                      projeto0_.totalRecursosProjeto as totalRe10_134_,
                      projeto0_.metaAtendimento as metaAte11_134_,
                      projeto0_.idEnquadramentoProjeto as idEnqua15_134_,
                      projeto0_.idStatus as idStatus134_ 
                  from
                      Projeto projeto0_,
                      Projeto_Categoria categorias1_,
                      Categoria categoria2_ 
                  where
                      projeto0_.id=categorias1_.Projeto_id 
                      and categorias1_.categorias_id=categoria2_.id 
                      and .=?
              



              why last


              and



              (in query)  has a


              .=?


              , i would that it were


              and categoria2_.id=?




              what i should do?

              • 5. Re: Restriction in EntityQuery (argument type mismatch)
                Dan Allen Master

                You cannot pass collections through parameters (unless you have a converter that can handle the translation). This is really pushing parameters too far and you should think about a long-running conversation and the <s:convertEntity> component on a UISelectMany input.

                • 6. Re: Restriction in EntityQuery (argument type mismatch)
                  Tiago Sudeval Newbie

                  Ok, but now i pass only a object ( categoria entity, it´s not collection) through parameters.



                  in projetoList.page.xml
                  ...
                  <param name="categoria" 
                        value="#{projetoList.parametrosProjetoBusca.categoria}"
                  converterId="CategoriaConverter"/>
                  ...
                  


                  in projetoList.xhtml
                  ... 
                  <s:decorate template="layout/display.xhtml">
                    <ui:define name="label">Categoria:</ui:define>
                    <h:selectOneMenu value="#{projetoList.parametrosProjetoBusca.categoria}">
                      <s:selectItems var="categoria"
                                   value="#{categoriaList.resultList}"
                                   label="#{categoria.nome}" 
                        noSelectionLabel="selecione uma categoria..."/>
                      <s:convertEntity/>
                    </h:selectOneMenu>
                  </s:decorate>
                  ...




                  ProjetoList.java
                  
                  is correct ?
                  
                  private static final String[] RESTRICTIONS = {
                  "projeto.categorias = (#{projetoList.parametrosProjetoBusca.categoria.id}) "
                  }
                  




                  entity
                  
                  Projeto {
                    @ManyToOne
                    List<Categoria> categorias;
                  }
                  



                  but my class EntityQuery (ProjetoList.java) not create a correct query :(
                  it´s possible resolved only with RESTRICTIONS this case ?