Scenario 1) The application deployed through the same EAR is able to register, look up, and instantiate Hibernate SessionFactory through JNDI.
Scenarion2) Two EARs are deployed with separate Application class loaders (default for WebSphere). The application in one EAR registers the Hibernate SessionFactory in JNDI. The other EAR is able to do the look up, however, it fails to instatiate the factory during lookup()
Context ctx = new InitialContext();
Object obj = ctx.lookup("MySessionFactory");
lookup() returns null and the following warning is issued from SessionFactoryObjectFactory:
[8/14/06 11:31:43:875 EDT] 0000002f SessionFactor W org.hibernate.impl.SessionFactoryObjectFactory getInstance Not found: 2c9097a20d0d4d8e010d0d4d94cd0000
Question: is the behavior in the second scenario by design i.e. two J2EE Applications loaded by different application loadeds are not able to register and instatiate a Hibernate SessionFactory through JNDI?
As a workaround, I placed the Hibernate library (and related libraries) into WAS_HOME/lib/ext/app which ensured that the two EARs share the same instance of Hibernate SessionFactory by being loaded by a common Extension class loader. However, cleaner solution would be to use JNDI for that purpose between multiple EARs.
|