7 Replies Latest reply on Dec 24, 2019 5:30 AM by zhurlik

    Hibernate listerner : Could not instantiate requested listener

    layoup

      Hi,

       

      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 ?

        • 1. Re: Hibernate listerner : Could not instantiate requested listener
          layoup

          To solve this issue, I am trying to install an wildfly module with application's hibernate listener.

          My module configuration is :

           

          <?xml version="1.0" encoding="UTF-8"?>
          
          
          <module name="fr.onf.socle.hibernate.listener" xmlns="urn:jboss:module:1.5">
          
          
              <resources>
                  <resource-root path="hibernate-listener-0.0.1-SNAPSHOT.jar"/>
              </resources>
          
          
              <dependencies>
                  <module name="org.hibernate" slot="5.3" />
              </dependencies>
          </module>
          

           

           

          I put this module.xml and jar with my 2 listeners in directory $JBOSS_HOME/modules/fr/onf/socle/hibernate/listener/main

          In my application I created an jboss-deployment-structure with this content :

           

          <jboss-deployment-structure>
              <deployment>
                  <dependencies>
                      <module name="fr.onf.socle.hibernate.listener" />            
                  </dependencies>
              </deployment>
          </jboss-deployment-structure>
          

           

          Sadly, it doesn't work but I am sur that is a good approach.

          What is your opinion ?

          • 2. Re: Hibernate listerner : Could not instantiate requested listener
            vrlgohel
            Do you see any error in the logs starting with *HHH* ? If yes, can you please attach the logs ?
            • 3. Re: Hibernate listerner : Could not instantiate requested listener
              layoup

              No log with level Error starting with HHH*. Only Warn (about generator duplicate name and composite-id without equals and hashCode) and Info.

              Error is always :

              10:20:38,580 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 79) 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
              
              
              10:20:38,615 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 1) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "teck-ear.ear")]) - failure description: {
                  "WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"teck-ear.ear/teck-services-4.6.1f.war#DefaultPersistenceUnit\"" => "javax.persistence.PersistenceException: [PersistenceUnit: DefaultPersistenceUnit] Unable to build Hibernate SessionFactory
                  Caused by: javax.persistence.PersistenceException: [PersistenceUnit: DefaultPersistenceUnit] Unable to build Hibernate SessionFactory
                  Caused by: org.hibernate.HibernateException: Could not instantiate requested listener [fr.onf.persistance.socle.listener.ONFEJB3FlushEntityEventListener, fr.onf.persistance.socle.listener.ControlVersionEntityEventListener]
                  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]
                  Caused by: java.lang.ClassNotFoundException: Could not load requested class : fr.onf.persistance.socle.listener.ONFEJB3FlushEntityEventListener, fr.onf.persistance.socle.listener.ControlVersionEntityEventListener"},
              

               

              Thanks a lot for your help.

              What I don't understand is how to give to Hibernate acces to my project's classes.

              I try to install an module with an jar including all my hibernate listener but it doesn't work.

              How to be sure that a module is effectively load on deployment ?

              How to be sure that my module is accessible by Hibernate module ?

               

              Best regards

              • 4. Re: Hibernate listerner : Could not instantiate requested listener
                zhurlik

                Hi,

                 

                My understanding is that hibernate module doesn't find you listeners.
                Could you try the following: modify hibernate module and add your module into dependencies inside hibernate, just to check it

                 

                Thanks,

                Vlad

                • 5. Re: Hibernate listerner : Could not instantiate requested listener
                  layoup

                  Hello,

                  Already tried but Wildfly doesn't start.

                  I will try another time because of I perhaps made a mistake first time.

                  Thanks for your reply

                   

                  Best regards

                  • 6. Re: Hibernate listerner : Could not instantiate requested listener
                    layoup

                    First time, I installed my custom module by hand but I made an mistake. I deleted what I did and use jboss-cli to create my custom module.

                    Now when I add my module as an dependency of hibernate module, wildfly start well but I have always an class not found for my listeners.

                    So only to try I removed my custom module from dependencies and added my jar as an resource root of wildfly's hibernate module.

                    It doesn't work !!!! Always an class not found.

                    I checked my jar and my two listeners are in.

                    I do not understand anything.

                    • 7. Re: Hibernate listerner : Could not instantiate requested listener
                      zhurlik

                      Hi,

                       

                      If you can extract your custom module that contains listeners, I can try to play locally with it.

                       

                      Thanks,

                      Vlad