I'm not using JPA. I've been moving all my components out of the ear(s) and into modules.
I'm running hibernate 5.2.5 so I added all the hibernate jars I needed into a module. All worked fine with most of the modules installed.
I moved a further bunch of my jars into modules and at that point I ran into exceptions on a call to Configuration.buildSessionFactory() -
14:35:59,995 ERROR [stderr] (org.bedework.bwengine:service=indexing) java.lang.RuntimeException: org.bedework.calfacade.exc.CalFacadeException: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
14:35:59,995 ERROR [stderr] (org.bedework.bwengine:service=indexing) at org.bedework.calendar.engine.impl//org.bedework.calsvc.CalSvc.getCal(CalSvc.java:1646)
14:35:59,995 ERROR [stderr] (org.bedework.bwengine:service=indexing) at org.bedework.calendar.engine.impl//org.bedework.calsvc.CalSvc.open(CalSvc.java:560)
14:35:59,995 ERROR [stderr] (org.bedework.bwengine:service=indexing) at org.bedework.calendar.engine.impl//org.bedework.calsvc.CalSvc.init(CalSvc.java:272)
Guessing this was an issue with class loaders I changed this in org/hibernate/proxy/pojo/javassist/JavassistProxyFactory.java
public static javassist.util.proxy.ProxyFactory buildJavassistProxyFactory(
final Class persistentClass,
final Class[] interfaces) {
javassist.util.proxy.ProxyFactory factory = new javassist.util.proxy.ProxyFactory() {
@Override
protected ClassLoader getClassLoader() {
return persistentClass.getClassLoader();
}
};
factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
factory.setInterfaces( interfaces );
factory.setFilter( FINALIZE_FILTER );
return factory;
}
to
public static javassist.util.proxy.ProxyFactory buildJavassistProxyFactory(
final Class persistentClass,
final Class[] interfaces) {
javassist.util.proxy.ProxyFactory factory = new javassist.util.proxy.ProxyFactory() {
@Override
protected ClassLoader getClassLoader() {
return Thread.currentThread().getContextClassLoader();
}
};
factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
factory.setInterfaces( interfaces );
factory.setFilter( FINALIZE_FILTER );
return factory;
}
That is - get the classloader from the current thread - not from the class.
One hibernate test did fail when I built hibernate - I commented it out and installed the jar with that one change. Now my application is working again.
This is a fairly old configuration - it's all done with xml mappings.
Is this an issue with hibernate? It seems to me that the class loader used should be the classloader for the running thread - which is presumably what I'd get if I loaded my classes as part of the ear.