0 Replies Latest reply on Aug 17, 2009 6:12 PM by asookazian

    Adding post-query filter

    asookazian

      I need to apply a post-query filter to my result set.  Just a NOT IN xyz and another one for IN xyz.  Otherwise, the select, from and where clause is almost identical for both queries.  Trying to avoid 2nd db hit.


      What's the best way to achieve this in Seam/JPA/Hibernate?  I already read about Hibnerate Filters which is not supported in JPA 1.0 or 2.0 but that does not apply in this scenario b/c you apply the filter (session.setEnable()) prior to the query execution:


      Session session = ...;
      session.enableFilter("effectiveDate").setParameter("asOfDate", new Date());
      List results = session.createQuery("from Employee as e where e.salary > :targetSalary")
               .setLong("targetSalary", new Long(1000000))
               .list();



      I need to filter in my Seam component after the List is populated.


      What's the best practice for this?  I can iterate through the entities in the list but that seems wierd, perhaps better to do the 2nd db hit?? thx.