I first posted this question in a reply on a thread:
Re: VPD mysteriously fails in ADF BC application, because reused connection ?
I thought I'd restate it in its own thread.
I have a JDeveloper/ADF 10.1.3.5 application. The schema that owns the database objects used by the application has created an Oracle Context named "TEDS_CTX" with the CREATE CONTEXT command. There is a PL/SQL package, TEDS_CTX_PKG that is authorized to set context variables in that context.
In the application, there is only one Application Module, TEDSAppModule. In TEDSAppModuleImpl.java, I have overridden prepareSession:
public void prepareSession(Session session) {
super.prepareSession(session);
//Retrieve the J2EE user ID
String authenticatedUser = getUserPrincipalName();
DBTransactionImpl dbTrans = (DBTransactionImpl)getDBTransaction();
CallableStatement cStmt =
dbTrans.createCallableStatement(("BEGIN " + "TEDS_CTX_PKG.SET_CURRENT_USER(?); " +
"END;"), 0);
try {
cStmt.setString(1, authenticatedUser);
cStmt.execute();
cStmt.close();
} catch (SQLException e) {
throw new JboException(e);
}
}
This works fine - TEDS_CTX gets set with the expected values. However, sometimes when more than one user, say UserA and UserB, is logged in at about the same time, I'll hear that UserA suddenly starts seeing stuff that should only be seen by UserB. For instance, if a table has an updated_by column that a trigger sets from Sys_Context('TEDS_CTX','CURRENT_USER'), and UserA updates a row, the updated_by column will contain 'UserB'.
So it looks like when UserB executes prepareSession, it replaces the information that UserA put into TEDS_CTX but UserA is still using that session. What should happen is that User A should keep the same database session and not share it with another user. If the session is passivated and the database session ended, then if it is re-activated, prepareSession ought to run again.
I suspect that this has something to do with the connection properties that I'm setting in the Application Module (bc4j.xcfg). I'm wondering if setting jbo.doconnectionpooling=true on the connection is the right way to handle this?