diff --git a/org.springframework.orm/src/main/java/org/springframework/orm/hibernate4/LocalSessionFactoryBean.java b/org.springframework.orm/src/main/java/org/springframework/orm/hibernate4/LocalSessionFactoryBean.java index 986e5e942f6..5af9396b3d1 100644 --- a/org.springframework.orm/src/main/java/org/springframework/orm/hibernate4/LocalSessionFactoryBean.java +++ b/org.springframework.orm/src/main/java/org/springframework/orm/hibernate4/LocalSessionFactoryBean.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.util.Properties; import javax.sql.DataSource; +import org.hibernate.Interceptor; import org.hibernate.SessionFactory; import org.hibernate.cfg.NamingStrategy; @@ -69,6 +70,8 @@ public class LocalSessionFactoryBean implements FactoryBean, Res private Resource[] mappingDirectoryLocations; + private Interceptor entityInterceptor; + private NamingStrategy namingStrategy; private Properties hibernateProperties; @@ -178,6 +181,16 @@ public class LocalSessionFactoryBean implements FactoryBean, Res this.mappingDirectoryLocations = mappingDirectoryLocations; } + /** + * Set a Hibernate entity interceptor that allows to inspect and change + * property values before writing to and reading from the database. + * Will get applied to any new Session created by this factory. + * @see org.hibernate.cfg.Configuration#setInterceptor + */ + public void setEntityInterceptor(Interceptor entityInterceptor) { + this.entityInterceptor = entityInterceptor; + } + /** * Set a Hibernate NamingStrategy for the SessionFactory, determining the * physical column and table names given the info in the mapping document. @@ -291,6 +304,10 @@ public class LocalSessionFactoryBean implements FactoryBean, Res } } + if (this.entityInterceptor != null) { + sfb.setInterceptor(this.entityInterceptor); + } + if (this.namingStrategy != null) { sfb.setNamingStrategy(this.namingStrategy); }