How to always enable Hibernate filters in a spring application?

Having an application based on the Hibernate (3.5) / Spring (3.0) / BlazeDS / Flex stack, 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 this hibernation session.

So my question is very simple: how can I enable all of the specific sleep filters as described above for all Hibernate sessions ? Is there a way to set up a Hibernate factory session in the spring xml configuration file to apply these filters?

+4
source share
2 answers

If you use the Spring HibernateTemplate, one of them is to extend and override the enableFilters method. In it, explicitly enable the filters you need.

+1
source

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

0
source

Source: https://habr.com/ru/post/1346793/


All Articles