title: enabling grails hibernate filters
body: <p>Hi I am using the <a href="http://www.grails.org/plugin/hibernate-filter" rel="nofollow">Grails filter plugin</a></p>
  
  <p>I am trying to define a default filter as below</p>
  
  <pre><code>// Defined inside the Book entity
  static hibernateFilters = {
      activeFilter(condition:'active=1', default:true)
  }
  </code></pre>
  
  <p>When i run my integration tests the filter does not apply for dynamic finder methods like </p>
  
  <pre><code>Book.findAll()
  </code></pre>
  
  <p>If I add the below line in the BootStrap.groovy class</p>
  
  <pre><code>Book.enableHibernateFilter('activeFilter')
  </code></pre>
  
  <p>Then the filter is applied.</p>
  
  <p>However when the application is run the filter is never applied, with or without the above code in BootStrap.groovy</p>
  
  <p>Any ideas ?</p>
  
  <p>After a little digging around this is what i have found</p>
  
  <p>The hibernate filter plugin works well without the zkgrails plugin however the two cannot seem to work together :(</p>
  
  <p>The below code snippet seems to be the problem for me.</p>
  
  <p>I think we could have two issues here</p>
  
  <p>1) Initially the execution gets to<br>
      all(controller:'<em>', action:'</em>')</p>
  
  <p>only once during application startup. I am thinking it should get there each time there is a new request and hence a new session.</p>
  
  <p>2) Even if it somehow gets there after certain modification, I do not think it'll get past 
      all(controller:'<em>', action:'</em>')</p>
  
  <p>composers are used in zkoss</p>
  
  <pre><code>class HibernateFilterFilters {
  
      def filters = {
          all(controller:'*', action:'*') {
              before = {
                  def session = grailsApplication.mainContext.sessionFactory.currentSession
                  DefaultHibernateFiltersHolder.defaultFilters.each {name -&gt;
                      session.enableFilter(name)
                  }
              }
              after = {
  
              }
              afterView = {
  
              }
          }
      }
  
  }
  </code></pre>