added "entityInterceptor" property to Hibernate 4 LocalSessionFactoryBean (SPR-8940)

master
Juergen Hoeller 13 years ago committed by Chris Beams
parent 00ff8fa2cc
commit eb31528979
  1. 17
      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<SessionFactory>, Res
private Resource[] mappingDirectoryLocations;
private Interceptor entityInterceptor;
private NamingStrategy namingStrategy;
private Properties hibernateProperties;
@ -178,6 +181,16 @@ public class LocalSessionFactoryBean implements FactoryBean<SessionFactory>, 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<SessionFactory>, Res
}
}
if (this.entityInterceptor != null) {
sfb.setInterceptor(this.entityInterceptor);
}
if (this.namingStrategy != null) {
sfb.setNamingStrategy(this.namingStrategy);
}

Loading…
Cancel
Save