I am using JPA with Hibernate as the provider on WebSphere.
Is there any way to fire a SQL statement when a new session is opened against the database. Ideally I would want to say when a new Connection is taken out of the pool and given to a thread to use I want to fire a statement.
The basic use case is it's a SET VARIABLE command which should be fired per logged on user (it's passing the userid of the user to the database, rather than the technical user which WebSphere's datasource is authenticating with).
So the SQL statement needs the logged in user id from the application. The statement cannot be configured to fire on the Application Server itself. All of my EntityManager interaction looks the same i.e.
@Stateless
@LocalBean
@Resource(name = "jdbc/ANY", type = javax.sql.DataSource.class,
authenticationType = AuthenticationType.CONTAINER, shareable = true)
public class MyRepository {
@PersistenceContext
private EntityManager entityManager;