Is there any way I can execute SQL from the setSessionContext() of a Stateless SessionBean using an xa-compliant JDBC driver?
I will describe the problem in detail.
- Weblogic server 6.1 SP2, Oracle 8.1.6
- SLSB needs to load a large amount of read-only data into cache from Oracle database.
- To do this, SLSB maintains a static cache of this data across all bean instances. The cache is initialized in setSessionContext() (only of not already initialized) and never modified subsequently.
- To make sure that the cache is initialized before users log in, the SessionBean pool is configured so that at least one bean instance is loaded on server startup.
Now, we come to the problem.
- We are using an XA compliant JDBC driver (weblogic.jdbc.oci.xa.XADataSource) to connect to Oracle.
- This driver expects a global xa transaction to be active, otherwise it throws a SQLException.
- When the Weblogic server starts up, it loads the bean and calls setSessionContext(). However, no transaction is active at this point, hence the SQL fails with a SQLException.
I thought of the following solutions:
1. Use a non-XA compliant driver, just for the data cacheing part since this does not require 2PC. The problem with this is, the caching strategy of one service (SLSB) determines the DAO implementation logic, effectively making the DAO non-reusable.
2. Define a method like initCache() (with TXN_REQUIRED attribute) on the SLSB remote interface and have a startup class call this method.
Is there a more generic solution to this problem?
Thanks for any tips