10 Replies Latest reply on Mar 1, 2018 1:06 AM by andey

    Unable to instantiate Scanner class - Hibernate 3.x deployment fails with WildFly

    begert

      I have a legacy Ear-Project that used Hibernate 3.6.6.Final (from JBoss6).

      Now I would like to deploy that Ear into Wildfly.

       

      I did everything mentioned here: Sharing the Hibernate 3.5 or greater JPA persistence provider between multiple applications

       

      My persistence.xml looks like this:

       

          <?xml version="1.0" encoding="UTF-8"?>

          <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">

              <persistence-unit name="pu">

                  <description></description>

                  <provider>org.hibernate.ejb.HibernatePersistence</provider>

                  <jta-data-source>java:/OracleDS</jta-data-source>

                  <properties>

                      <property name="jboss.as.jpa.providerModule" value="org.hibernate:3" />

                      <property name="hibernate.session_factory_name" value="hibernate/HelperSessionFactory" />

                      <property name="hibernate.session_factory_name_is_jndi" value="true" />

                  </properties>

              </persistence-unit>

          </persistence>

       

      I added

      Dependencies: org.hibernate:3

      to the MANIFEST.MF

       

      But the Deployment fails with the following error:

       

          17:03:13,125 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 52) MSC000001: Failed to start service jboss.persistenceunit."HelperEJB.ear/HelperEJB.jar#pu": org.jboss.msc.service.StartException in service jboss.persistenceunit."HelperEJB.ear/HelperEJB.jar#pu": javax.persistence.PersistenceException: [PersistenceUnit: pu] Unable to instantiate Scanner class: class org.jboss.as.jpa.hibernate3.HibernateAnnotationScanner

                  at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]

                  at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]

                  at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.8.0]

                  at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:474)

                  at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]

                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0]

                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0]

                  at java.lang.Thread.run(Thread.java:744) [rt.jar:1.8.0]

                  at org.jboss.threads.JBossThread.run(JBossThread.java:122)

          Caused by: javax.persistence.PersistenceException: [PersistenceUnit: pu] Unable to instantiate Scanner class: class org.jboss.as.jpa.hibernate3.HibernateAnnotationScanner

                  at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1225)

                  at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.locateOrBuildScanner(EntityManagerFactoryBuilderImpl.java:767)

                  at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.scan(EntityManagerFactoryBuilderImpl.java:720)

                  at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:219)

                  at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:186)

                  at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:45)

                  at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:57)

                  at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:150)

                  at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:67) [hibernate-entitymanager.jar:3.6.6.Final]

                  at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:318) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]

                  at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.access$1100(PersistenceUnitServiceImpl.java:67) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]

                  at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:167) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]

                  ... 8 more

          Caused by: java.lang.ClassCastException: org.jboss.as.jpa.hibernate3.HibernateAnnotationScanner cannot be cast to org.hibernate.jpa.boot.scan.spi.Scanner

                  at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.locateOrBuildScanner(EntityManagerFactoryBuilderImpl.java:764)

                  ... 18 more

       

      I can't figure out what I'm doing wrong!

        • 1. Re: Unable to instantiate Scanner class - Hibernate 3.x deployment fails with WildFly
          smarlow

          Do you have Hibernate jars in your HelperEJB.ear?

           

          Please show us the contents of your wildfly-8.0.0.Final/modules/system/layers/base/org/hibernate/3 folder and the contents of the wildfly-8.0.0.Final/modules/system/layers/base/org/hibernate/3/module.xml file.

           

          Please enable TRACE logging for org.jboss.as.jpa (how to is here) and post the deployment output here.

          • 2. Re: Unable to instantiate Scanner class - Hibernate 3.x deployment fails with WildFly
            begert

            Thanks for your answer!

             

            I copied the three jars from our actual JBoss (JBossAS [6.1.0.Final "Neo"]) from the directory commons\lib into the hibernate/3 module.

            This jars i have copied into E:\wildfly-8.0.0.Final\modules\system\layers\base\org\hibernate\3

             

            05.03.png

             

            This is the content of module.xml:

             

            <module xmlns="urn:jboss:module:1.1" name="org.hibernate" slot="3">

                <resources>

                    <resource-root path="jipijapa-hibernate3-1.0.1.Final.jar"/>

                    <resource-root path="hibernate-core.jar"/>

                    <resource-root path="hibernate-commons-annotations.jar"/>

                    <resource-root path="hibernate-entitymanager.jar"/>

                </resources>

             

                <dependencies>

                    <module name="asm.asm"/>

                    <module name="javax.api"/>

                    <module name="javax.annotation.api"/>

                    <module name="javax.enterprise.api"/>

                    <module name="javax.persistence.api"/>

                    <module name="javax.transaction.api"/>

                    <module name="javax.validation.api"/>

                    <module name="javax.xml.bind.api"/>

                    <module name="org.antlr"/>

                    <module name="org.apache.commons.collections"/>

                    <module name="org.dom4j"/>

                    <module name="org.javassist"/>

                    <module name="org.jboss.as.jpa.spi"/>

                    <module name="org.jboss.as.jpa.util"/>

                    <module name="org.jboss.jandex"/>

                    <module name="org.jboss.logging"/>

                    <module name="org.jboss.vfs"/>

                </dependencies>

            </module>

             

            Here is the full log from the Deployment with TRACE enabled: gist:3e2280c00c10e6acd76b

            • 3. Re: Unable to instantiate Scanner class - Hibernate 3.x deployment fails with WildFly
              smarlow

              In the TRACE output, I can see that we are using Hibernate 4.3.1 jars instead of 3.6.6.  I created WFLY-3074 for this bug.

               

              We have a unit test that bundles the Hibernate 3.6.x jars with the deployment and that passes.  I have a new local unit test that seems to recreate your issue as well.

               

              Thanks for reporting this.

               

              Scott

              1 of 1 people found this helpful
              • 4. Re: Unable to instantiate Scanner class - Hibernate 3.x deployment fails with WildFly
                begert

                Thanks Scott!

                 

                I tried to bundle Hibernate 3 with my EAR as a workaround.

                This works, but now I have another problem when I try to rename the SessionFactory-Name like this

                 

                     <property name="hibernate.session_factory_name" value="hibernate/HelperSessionFactory" />

                     <property name="hibernate.session_factory_name_is_jndi" value="true" />

                 

                This throws a NullPointer here

                 

                10:21:58,009 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 54) MSC000001: Failed to start service jboss.persistenceunit."HelperEJB.ear/HelperEJB.jar#pu": org.jboss.msc.service.StartException in service jboss.persistenceunit."HelperEJB.ear/HelperEJB.jar#pu": java.lang.NullPointerException

                        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]

                        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]

                        at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.8.0]

                        at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:474)

                        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]

                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0]

                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0]

                        at java.lang.Thread.run(Thread.java:744) [rt.jar:1.8.0]

                        at org.jboss.threads.JBossThread.run(JBossThread.java:122)

                Caused by: java.lang.NullPointerException

                        at org.jboss.as.naming.WritableServiceBasedNamingStore.rebind(WritableServiceBasedNamingStore.java:120)

                        at org.jboss.as.naming.NamingContext.rebind(NamingContext.java:274)

                        at org.hibernate.util.NamingHelper.bind(NamingHelper.java:97) [hibernate-core.jar:3.6.6.Final]

                        at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:113) [hibernate-core.jar:3.6.6.Final]

                        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:367) [hibernate-core.jar:3.6.6.Final]

                        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872) [hibernate-core.jar:3.6.6.Final]

                        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906) [hibernate-entitymanager.jar:3.6.6.Final]

                        at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74) [hibernate-entitymanager.jar:3.6.6.Final]

                        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:318) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]

                        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.access$1100(PersistenceUnitServiceImpl.java:67) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]

                        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:167) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]

                        ... 8 more

                • 5. Re: Re: Unable to instantiate Scanner class - Hibernate 3.x deployment fails with WildFly
                  smarlow

                  What happens if you change to:

                  <property name="hibernate.session_factory_name" value="HelperSessionFactory" />

                   

                  If you feel like building WildFly from my branch, it might be interesting to see if that helps you with creating the Hibernate 3 static module.  I was able to get my unit test working with this change.

                  • 6. Re: Unable to instantiate Scanner class - Hibernate 3.x deployment fails with WildFly
                    smarlow

                    You can also watch the pull request link.  When that is merged + closed, you can grab the nightly build on the next day to try the change.  The WildFly nightly build is available here.

                    • 7. Re: Unable to instantiate Scanner class - Hibernate 3.x deployment fails with WildFly
                      begert

                      Your branch works! But the NullPointer persists when I set the hibernate.session_factory_name property, even if I remove the "hibernate/".

                      I will try this again later, but thanks for your help!

                      • 8. Re: Re: Unable to instantiate Scanner class - Hibernate 3.x deployment fails with WildFly
                        smarlow

                        Have you tried injecting the session factory as a workaround?  Example from the JPA documentation

                        import org.hibernate.SessionFactory;
                        @Stateful public class MyStatefulBean ... {
                           @PersistenceUnit(unitName="mypu") SessionFactory factory;
                        }
                        

                         

                        We started supporting the above injection for AS 5 and I know it works with Hibernate ORM 4.3.x (should also work with 3.6.x).

                        • 9. Re: Unable to instantiate Scanner class - Hibernate 3.x deployment fails with WildFly
                          virendra656

                          Hello Scott,

                           

                          My problem is somehow same can you please let me know hat changes i need to make in order to deploy successfully.

                           

                          persistent.xml =>

                          <?xml version="1.0" encoding="UTF-8"?>

                          <persistence xmlns="http://java.sun.com/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_1_0.xsd" version="1.0" >

                             <persistence-unit name='ipem'>

                            

                             <jta-data-source>java:/StudentMgtDS</jta-data-source>

                             <properties>

                                <property name="jboss.entity.manager.jndi.name" value="java:EntityManager/ipem"/>

                                <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />

                                <property name="hibernate.hbm2ddl.auto" value="update"/>

                                <property name="hibernate.jdbc.batch_size" value="250"/>

                                <property name="hibernate.jdbc.batch_versioned_data" value="true"/>

                                <property name="hibernate.id.new_generator_mappings" value="false"/>

                                <property name="jboss.as.jpa.providerModule" value="org.hibernate:3" />

                               

                                <!-- END MRS 12-19-05 -->

                               

                             </properties>  

                            </persistence-unit> 

                             

                            </persistence>

                           

                           

                          module.xml =>

                           

                          <?xml version="1.0" encoding="UTF-8"?>

                          <!-- Represents the Hibernate 3.x module  -->

                          <module xmlns="urn:jboss:module:1.3" name="org.hibernate" slot="3">

                              <resources>

                           

                          <!-- <resource-root path="slf4j-api-1.5.6.jar"/>

                          <resource-root path="slf4j-log4j12-1.5.6.jar"/>

                          <resource-root path="log4j.jar"/> -->

                                  <resource-root path="hibernate-commons-annotations-3.2.0.Final.jar"/>

                          <resource-root path="hibernate-core-3.6.10.Final.jar"/>

                          <resource-root path="hibernate-entitymanager-3.6.10.Final.jar"/>

                          <resource-root path="jipijapa-hibernate3-1.0.1.Final.jar"/>

                              </resources>

                           

                           

                              <dependencies>

                                  <module name="asm.asm"/>

                                  <module name="javax.api"/>

                                  <module name="javax.annotation.api"/>

                                  <module name="javax.enterprise.api"/>

                                  <module name="javax.persistence.api"/>

                                  <module name="javax.transaction.api"/>

                                  <module name="javax.validation.api"/>

                                  <module name="javax.xml.bind.api"/>

                                  <module name="org.antlr"/>

                                  <module name="org.apache.commons.collections"/>

                                  <module name="org.dom4j"/>

                                  <module name="org.javassist"/>

                                  <module name="org.jboss.as.jpa.spi"/>

                                  <module name="org.jboss.jandex"/>

                                  <module name="org.jboss.logging"/>

                                  <module name="org.jboss.vfs"/>

                              </dependencies>

                          </module>

                           

                          Error logs =>

                           

                          "{

                              \"WFLYCTL0080: Failed services\" => {

                                  \"jboss.deployment.subunit.\\\"x3.ear\\\".\\\"x3.war\\\".INSTALL\" => \"org.jboss.msc.service.StartException in service jboss.deployment.subunit.\\\"x3.ear\\\".\\\"x3.war\\\".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of subdeployment \\\"x3.war\\\" of deployment \\\"x3.ear\\\"

                              Caused by: java.util.ConcurrentModificationException\",

                                  \"jboss.persistenceunit.\\\"x3.ear/x3.jar#ipem\\\"\" => \"org.jboss.msc.service.StartException in service jboss.persistenceunit.\\\"x3.ear/x3.jar#ipem\\\": javax.persistence.PersistenceException: [PersistenceUnit: ipem] Unable to instantiate Scanner class: class org.jboss.as.jpa.hibernate3.HibernateAnnotationScanner

                              Caused by: javax.persistence.PersistenceException: [PersistenceUnit: ipem] Unable to instantiate Scanner class: class org.jboss.as.jpa.hibernate3.HibernateAnnotationScanner

                              Caused by: java.lang.ClassCastException: org.jboss.as.jpa.hibernate3.HibernateAnnotationScanner cannot be cast to org.hibernate.jpa.boot.scan.spi.Scanner\"

                              },

                              \"WFLYCTL0180: Services with missing/unavailable dependencies\" => [

                                  \"jboss.deployment.subunit.\\\"x3.ear\\\".\\\"x3.war\\\".batch.environment is missing [jboss.deployment.subunit.\\\"x3.ear\\\".\\\"x3.war\\\".beanmanager]\",

                                  \"jboss.deployment.unit.\\\"x3.ear\\\".deploymentCompleteService is missing [jboss.deployment.subunit.\\\"x3.ear\\\".\\\"x3.war\\\".deploymentCompleteService]\",

                                  \"jboss.deployment.unit.\\\"x3.ear\\\".WeldStartService is missing [jboss.deployment.subunit.\\\"x3.ear\\\".\\\"x3.war\\\".jndiDependencyService]\"

                              ]

                          }"

                          • 10. Re: Unable to instantiate Scanner class - Hibernate 3.x deployment fails with WildFly
                            andey

                            Workaround is to bundle Hibernate 3 jars with application. there is s bug opened for this: [WFLY-3074] Hibernate 3.x static module cannot be used - JBoss Issue Tracker