Interceptor do Hibernate não funciona
Eu tenho um HibernateInterceptor simples em que basicamente eu quero definir alguns campos automaticamente. Este interceptor (mostrado abaixo) estende o EmptyInterceptor:
<code>public class EntityAuditInterceptor extends EmptyInterceptor { /** * The Serial Version UUID. */ private static final long serialVersionUID = 4636626262147801287L; /* (non-Javadoc) * @see org.hibernate.EmptyInterceptor#onFlushDirty(java.lang.Object, java.io.Serializable, java.lang.Object[], java.lang.Object[], java.lang.String[], org.hibernate.type.Type[]) */ public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) { // doing stuff here return false; } /* (non-Javadoc) * @see org.hibernate.EmptyInterceptor#onSave(java.lang.Object, java.io.Serializable, java.lang.Object[], java.lang.String[], org.hibernate.type.Type[]) */ public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) { // doing stuff here return false; } } </code>
Estou conectando usando um arquivo de configuração de mola da seguinte maneira:
<code><!-- Hibernate SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="hsqlDbDataSource"/> <property name="packagesToScan"> <list> <value>com.dreamteam.lms.**.*</value> </list> </property> <!-- Adding Interceptor here --> <property name="entityInterceptor"> <bean class="com.dreamteam.lms.interceptors.EntityAuditInterceptor"></bean> </property> <property name="hibernateProperties"> <props> <!--<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>--> <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop> <prop key="hibernate.generate_statistics">true</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.cache.use_second_level_cache">true</prop> <prop key="hibernate.hbm2ddl.auto">create</prop> <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop> </props> </property> </bean> </code>
No entanto, o interceptador nunca é alcançado. Alguem tem alguma ideia? Também tentei incluir o seguinte na definição do bean do gerenciador de transações da seguinte maneira:
<code><property name="entityInterceptor"> <ref local="entityAuditInterceptor"/> </property> </code>