My web application runs on Tomcat 7.0 and uses Spring 3.2, Hibernate 4.3 and Oracle Database.
The entityManagerFactory is configured as org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
and the transactionManager is org.springframework.orm.jpa.JpaTransactionManager
. The dataSource is defined as org.springframework.jndi.JndiObjectFactoryBean
and internally refers to a connection pool of type org.apache.tomcat.jdbc.pool.DataSourceFactory
.
Each time when a connection is fetched from the pool by the entityManager, I'd like to execute a custom sql statement in that connection. It will only change a property in the Oracle session context, like so:
dbms_session.set_context(context, propName, propValue);
So no dml is done.
Each time when a connection is released back to the pool, a similar statement should be executed to clear the property value.
The property value should be fetched dynamically from the spring-security context, so I can't hardcode this into a connection test statement.
I've also looked into Hibernate interceptors, but I've found no way to execute any sql in the same session from within an interceptor.
Any ideas?