How to always enable my Hibernate filters in a spring application?

3.5k views Asked by At

Having a Hibernate (3.5)/Spring (3.0)/BlazeDS/Flex stack-based application, I need to apply filters for some of my domain classes as shown below.

@FilterDef(name="notDeletedFilter")
@Filter(name="notDeletedFilter", condition="deleted=0")
public class Item {
   private boolean deleted;
  //setter and getter
}

These filters should always be applied in my application. However, according to the hibernate documentation, by default, filters are not enabled for a given hibernate session.

So my question is very simple: How can I enable all defined hibernate filters as above for all Hibernate sessions? Is there anyway to configure my Hibernate Session factory in a spring xml configuration file in order to apply these filters?

2

There are 2 answers

4
Brent Worden On

If you are using Spring's HibernateTemplate, one solution is to extend it and override the enableFilters method. In it, explicitly enable the filters you need.

1
Arun R On

You could use AOP (aspect oriented programming) to configure the filter.