I\'d like to set a database session variable for every session from Eclipselink. The SQL I want to execute is something like:
begin DBMS_SESSION.SET_IDENTIF
You are executing a query on the session while it is still obtaining a connection for some other process. The connection the postConnect event is triggered for is unavailable to the session until your event finishes - that means any query on the session will be forced to obtain a different connection.
You need to use the accessor within the SessionEvent to obtain the connection and use it to directly execute a JDBC statement. Something like
public void postConnect(SessionEvent evt) {
Connection connection = ((Accessor)event.getResult()).getConnection()
Statement statement = connection.createStatement();
statement.execute("begin DBMS_SESSION.SET_IDENTIFIER('MyApplicationName'); end;");
}