Hi,
I sometimes get a ClassCastException when looking up a SessionFactory from JNDI in a Websphere cluster. It seems the Reference object is obtained from another node in the cluster and the UUID instance does not match with any SessionFactory in the current JVM.
Going through the SessionFactoryImpl, the getReference method is implemented as:
Code:
public Reference getReference() {
// from javax.naming.Referenceable
LOG.debug( "Returning a Reference to the SessionFactory" );
return new Reference(
SessionFactoryImpl.class.getName(),
new StringRefAddr("uuid", getUuid()),
SessionFactoryRegistry.ObjectFactoryImpl.class.getName(),
null
);
}
The SessionFactory name is not used in this Reference.
On Websphere I get the error:
Code:
NMSV0609W: A Reference object looked up from the context "<cluster name>" with the name "<session factory name>" was sent to the JNDI Naming Manager and was returned unprocessed. Reference data follows:
Reference Factory Class Name: org.hibernate.internal.SessionFactoryRegistry$ObjectFactoryImpl
Reference Factory Class Location URLs: <null>
Reference Class Name: org.hibernate.internal.SessionFactoryImpl
Type: uuid
Content: 95378527-0b22-4bd2-a143-69b8560a9b36
The InitialContext.lookup() call returns the Reference causing a ClassCastException when casting to a SessionFactory.
I use 4.2.7 in production, but this code is also present in the latest code from GitHub.
Is there anyone who has faced this issue and resolved it? As I mentioned before, this error is intermittent.
Thanks,
Deepu