Hibernate, wildfly modules and class loaders.

162 views
Skip to first unread message

Mike Douglass

unread,
Feb 22, 2021, 2:38:40 PM2/22/21
to WildFly
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.

Scott Marlow

unread,
Apr 20, 2022, 1:56:13 PM4/20/22
to WildFly
Have you tried setting a debugger breakpoint where the exception is caught and a throws the MappingException via https://github.com/hibernate/hibernate-orm/blob/5.2/hibernate-core/src/main/java/org/hibernate/persister/internal/PersisterFactoryImpl.java#L123 ?

I don't see the catch exception in the information you posted above.  If you are changing code, perhaps you could also update the code throwing the exception to call e.printStackTrace() before throwing the new MappingException so that you can see the exception in the WildFly console or server.log. 

Scott
Reply all
Reply to author
Forward
0 new messages