3 Replies Latest reply on Mar 24, 2010 8:25 PM by Raphael Rodrigues

    Hibernate Filter with IN

    Raphael Rodrigues Newbie

      Hi,

      In my project, I have one filter in components.xml. Like this:

             

      In my entity class, I put @FilterDef and @Filter.

      @FilterDef(name="distribuidores",  parameters={ @ParamDef(name="codDistribuidor",type="string")})
      @Filter(name="distribuidores", condition="actcoddistribuidor in :codDistribuidor")

      The variable value is setting in Authenticator normally. However, the filter is not setted in my entity query. If I change to condition="actcoddistribuidor = :codDistribuidor" and my variable to simple String, works.

      What's the correct way to work with IN in my condition?

      Cheers,
      Raphael

        • 1. Re: Hibernate Filter with IN
          Raphael Rodrigues Newbie

          Raphael  Rodrigues wrote on Aug 13, 2009 23:42:


          Hi,

          In my project, I have one filter in components.xml. Like this:

                  <persistence:managed-persistence-context
                          name="entityManager" auto-create="true"
                          entity-manager-factory="#{ActiviaWebEntityManagerFactory}">
                      <persistence:filters>
                          <value>#{distribuidores}</value>
                        </persistence:filters>
                  </persistence:managed-persistence-context>               
                 
                  <persistence:filter name="distribuidores" enabled="#{listaDistribuidores != null and listaDistribuidores.size >0}">
                    <persistence:name>distribuidores</persistence:name>
                    <persistence:parameters>
                      <key>codDistribuidor</key>
                      <value>#{listaDistribuidores}</value>
                    </persistence:parameters>
                  </persistence:filter>

          In my entity class, I put @FilterDef and @Filter.

          @FilterDef(name="distribuidores",  parameters={ @ParamDef(name="codDistribuidor",type="string")})
          @Filter(name="distribuidores", condition="actcoddistribuidor in :codDistribuidor")

          The variable value is setting in Authenticator normally. However, the filter is not setted in my entity query. If I change to condition="actcoddistribuidor = :codDistribuidor" and my variable to simple String, works.

          What's the correct way to work with IN in my condition?

          Cheers,
          Raphael



          Click HELP for text formatting instructions. Then edit this text and check the preview.

          • 2. Re: Hibernate Filter with IN
            Busssard Buss Newbie
            Hi Raphael,

            I hope you resolved this problem by now, but if someone else need this information here is a shortcut:

            Reading this post in hybernate forum:

            https://forum.hibernate.org/viewtopic.php?t=934226&highlight=filterparam

            In seam code you can follow this tutorial (thanks Craig ) :

            https://sites.google.com/a/softwarefactory.co.nz/seam-tips/other/hibernate-filters

            but in your default condition use something like "organization_id in (:org_id)" and in persistence parameters value use a List type variable. Don't change  the type in ParamDef !

            Perhaps this information help somebody :)
            • 3. Re: Hibernate Filter with IN
              Raphael Rodrigues Newbie

              Buss,


              i solved this issue a few weeks ago... In fact, i was doing something wrong, but i didn't remember anymore. Thanks a lot for your answer.