I want to interceptor to the data fetch from database using hibernate that if in my data, particular field is present then get the value and check if that value is applicable to the user who queried it.
My application uses spring mvc with hibernate. I have configured an interceptor at session factory level.
class AuditInterceptor extends EmptyInterceptor {
@Override
public Object instantiate(String entityName, EntityMode entityMode, Serializable id) {
System.out.println("******************************* instantiated ****************************");
return null;
}
@Override
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
System.out.println("******************************* on load ****************************");
return true;
}
}
In my spring-dao.xml
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="c3p0DataSource" />
<property name="packagesToScan">
...
</property>
<property name="hibernateProperties">
....
</property>
<property name="entityInterceptor">
<bean class="com.hibernate.AuditInterceptor" />
</property>
</bean>
I want whenever query.list() excutes it should be able to intercept data using above inteceptor.
Now, it is calling my interceptor when my application starts. I am not able to get data for validation.(I want to perform validation in interceptor)