4 Replies Latest reply on Mar 24, 2010 3:12 PM by Busssard Buss

    Hibernate Filter really work with seam ???

    Busssard Buss Newbie

      Hello all,


      Is it a bug with seam ? (My version is 2.2.1.CR1)


      I tried this:


      http://www.next-presso.fr/2008/10/how-to-use-hibernate-filters-in-seam/lang/en


      and this


      http://www.redhat.com/docs/manuals/jboss/jboss-eap-4.2/doc/seam/SeamReferenceGuide/SeamandObjectRelationalMapping-UsingtheJPAdelegate.html


      and this


      http://relation.to/2002.lace


      Filter is a great feature of Hibernate and could turn my life a lot of easy.


      Any one has implemented hibernate filters with seam ???

        • 1. Re: Hibernate Filter really work with seam ???
          Stuart Douglas Master

          It works fine.


          If you need help you need to post details of what you have tried and the error you are getting.

          • 2. Re: Hibernate Filter really work with seam ???
            Busssard Buss Newbie

            Hi Stuart,


            I was following this tutorial


            http://www.next-presso.fr/2008/10/how-to-use-hibernate-filters-in-seam/lang/en


            I simplify the example trying to find the error and in my components.xml I edited like this:




               <!-- Create the Filter without parameters for while -->
               <persistence:filter name="filterClasse" enabled="#{true}">
                   <persistence:name>filtroClasse</persistence:name>
               </persistence:filter>
            
               <!--  Configure the filter to use with the  Default Entity Maneger -->
               <persistence:managed-persistence-context name="entityManager" auto-create="true"
                                  persistence-unit-jndi-name="java:/metasEntityManagerFactory">
                   <persistence:filters>
                     <value>#{filterClasse}</value>
                   </persistence:filters>
               </persistence:managed-persistence-context>
            
              
               <!-- Only for test with enableFilter() function -->
               <factory name="session" 
                         scope="STATELESS" 
                         auto-create="true" 
                         value="#{entityManager.delegate}"/>
            





            and at my class:




            @org.hibernate.annotations.FilterDef(name = "filtroClasse")
            @Entity
            @Table(name = "META2", schema = "ESTATISTICA")
            @org.hibernate.annotations.Filter(name = "filtroClasse", condition="MES = 'XX'" )






            As you can read above I'm trying a static condition first, but I want to use parameters too.


            Where are my mistakes ?

            • 3. Re: Hibernate Filter really work with seam ???
              Craig Bensemann Novice

              So do you get any errors with the above configuration? Please post these if you did. I know I was a bit confused when I created my first filter in Seam. The docs don't really cover this well. I also basically followed the tutorial you did and afterwards I typed up a summary of what I did on my seam tips pages https://sites.google.com/a/softwarefactory.co.nz/seam-tips/other/hibernate-filters. It basically repeats what was stated in the tutorial you have already found but maybe reading it stated in a slightly different way with different examples may help.


              If you get it set up correctly and have enabled hibernate printing of sql you should see your condition printed out as a where clause in queries using the filter.


              • 4. Re: Hibernate Filter really work with seam ???
                Busssard Buss Newbie

                Thanks Craig,


                I follow your steps and its works. I realy don't know what was my mistake, but now it works !