Hibernate listerner : Could not instantiate requested listener
layoup Dec 18, 2019 7:58 AMHi,
I try to migrate applications from an Glassfish 3.1.2.2 to an Wildfly 18 server.
Applications are quite old and use hibernate 3.6.8 Final.
I read that Wildfly come with different versions of hibernate in modules. I decided to use the most recent available version package with Wildfly 18, 5.3.13 Final.
So I tried to migrate one of my applications. I modified pom.xml of this application to have an dependancie to hibernate 5.3.13.Final with provided scope.
I modified my persistence.xml and fix some classes. Now my project compile fine.
Here is my perrsistence.xml
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="DefaultPersistenceUnit" transaction-type="JTA"> <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> <jta-data-source>java:/teckDataSource</jta-data-source> <properties> <!-- Classes persistantes --> <property name="use_sql_comments" value="true" /> <!-- Parametrage de JTA --> <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" /> <property name="hibernate.transaction.factory_class" value="org.hibernate.ejb.transaction.JoinableCMTTransactionFactory" /> <property name="jta.UserTransaction" value="java:jboss/UserTransaction" /> <!-- Parametrage module hibernate wildfly --> <!-- <property name="jboss.as.jpa.providerModule" value="org.hibernate:4.1"/> --> <property name="hibernate.jpa.compliance.global_id_generators" value="false"/> <!-- Dialecte de la base de donnees --> <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" /> <!-- batching size --> <property name="hibernate.jdbc.batch_size" value="30" /> <property name="hibernate.order_inserts" value="true" /> <property name="hibernate.order_updates" value="true" /> <property name="hibernate.jdbc.batch_versioned_data" value="true" /> <!-- Modification de l'interprétation de la valeur d'allocation des séquences conformément la norme JPA --> <property name="hibernate.id.new_generator_mappings" value="true" /> <property name="hibernate.id.optimizer.pooled.prefer_lo" value="true" /> <!-- Parametrage du listener de controle du numéro de version --> <property name="hibernate.ejb.event.flush-entity" value="fr.onf.persistance.socle.listener.ONFEJB3FlushEntityEventListener, fr.onf.persistance.socle.listener.ControlVersionEntityEventListener" /> </properties> </persistence-unit> </persistence>
Nevertheless when I tried to deploy my project, deployement stops with this message :
19:41:18,978 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 78) MSC000001: Failed to start service jboss.persistenceunit."teck-ear.ear/teck-services-4.6.1f.war#DefaultPersistenceUnit": org.jboss.msc.service.StartException in service jboss.persistenceunit."teck-ear.ear/teck-services-4.6.1f.war#DefaultPersistenceUnit": javax.persistence.PersistenceException: [PersistenceUnit: DefaultPersistenceUnit] Unable to build Hibernate SessionFactory
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:198)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:128)
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:658)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:212)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.lang.Thread.run(Thread.java:748)
at org.jboss.threads.JBossThread.run(JBossThread.java:485)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: DefaultPersistenceUnit] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1016)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:942)
at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:170)
... 9 more
Caused by: org.hibernate.HibernateException: Could not instantiate requested listener [fr.onf.persistance.socle.listener.ONFEJB3FlushEntityEventListener, fr.onf.persistance.socle.listener.ControlVersionEntityEventListener]
at org.hibernate.internal.SessionFactoryImpl.instantiate(SessionFactoryImpl.java:423)
at org.hibernate.internal.SessionFactoryImpl.prepareEventListeners(SessionFactoryImpl.java:413)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:207)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:939)
... 11 more
Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [fr.onf.persistance.socle.listener.ONFEJB3FlushEntityEventListener, fr.onf.persistance.socle.listener.ControlVersionEntityEventListener]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:134)
at org.hibernate.internal.SessionFactoryImpl.instantiate(SessionFactoryImpl.java:420)
... 15 more
Caused by: java.lang.ClassNotFoundException: Could not load requested class : fr.onf.persistance.socle.listener.ONFEJB3FlushEntityEventListener, fr.onf.persistance.socle.listener.ControlVersionEntityEventListener
at org.hibernate.boot.registry.classloading.internal.AggregatedClassLoader.findClass(AggregatedClassLoader.java:210)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:131)
... 16 more
I think that is an classloader issue. Hibernate can't reached my application classes because of classloader hierarchy.
Someone clould me explain how to deals with this situation ?