How to always enable my Hibernate filters in a spring application?
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 Hibernat开发者_如何转开发e Session factory in a spring xml configuration file in order to apply these filters?
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.
You could use AOP (aspect oriented programming) to configure the filter.
精彩评论