5 Replies Latest reply on Sep 21, 2011 10:27 AM by smarlow

    Jboss AS 7 + Hibernate 4

    shankarm

      I was using Hibernate 3 under JBoss 4.x. Now we are planning to migrate to JBoss AS7 that provides Hibernate 4 by default. We were using some of the classes org.hibernate.event.* (i.e. FlushEntityEvent, FlushEntityEventListener etc.) which I found missing in hibernate4.

       

      Can some one guide me where to find those classes in hibernate 4? If those are discontinued, is there any substiture to migrate?

       

      Thanks in advance!

      Shankar

        • 1. Re: Jboss AS 7 + Hibernate 4
          shankarm

          Can I use hibernate 3 with Jboss AS 7?

          • 2. Re: Jboss AS 7 + Hibernate 4
            smarlow

            The package name changed, try org.hibernate.event.spi,FlushEntityEventListener.

             

            https://docs.jboss.org/author/display/AS7/JPA+Reference+Guide describes how you can get started with Hibernate 3.5 or later on AS7.  This is supported for migration purposes (to make it easier to move your applications to AS7, before you switch to Hibernate 4). 

             

            If your using earlier versions of Hibernate 3.x (e.g. 3.3.x), I can point you to a JIRA that has some notes on that.

             

            Are you using JPA or the native Hibernate api? 

            • 3. Re: Jboss AS 7 + Hibernate 4
              shankarm

              Scott,

              Thanks for your prompt response. I am using older version(3.4) of hibernate  (i.e. prior to 3.5). It will be good if you can point me to JIRA notes.

              Regarding API, we are using JPA API, but at places we have used hibernate classes as well for lifecycle management of entities.

               

              Also,

              It looks some validations for annotations has also put in place in Hibernate 4 as I am getting follwing errors with Hibernate 4:

               

              Caused by: org.hibernate.AnnotationException: Associations marked as mappedBy must not define database mappings like @JoinTable or @JoinColumn: com.avaya.panther.config.rts.service.common.entity.ApplicationSystemTypeEntity.aAppSystemTypeAssignEntity

                      at org.hibernate.cfg.annotations.CollectionBinder.bind(CollectionBinder.java:483)

                      at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1910)

                      at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:761)

                      at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:682)

                      at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3381)

                      at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3335)

                      at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1319)

                      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1709)

                      at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:76)

                      at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:894)

                      ... 9 more

               

               

               

               

              Thanks,

              Shankar

              • 4. Re: Jboss AS 7 + Hibernate 4
                shankarm

                Tried using Hibernate 3.4 with Jboss AS 7 and followed instructions provided in Developers Guide for configuring Hibernate3 module. I got following errors:

                 

                Looks like , need to upgrade to at least hibernate 3.5

                 

                jboss.as.jpa.hibernate:3" from local module loader @12c7568 (roots: /opt/Avaya/jboss-as-7.0.1.Final/modules): java.lang.LinkageError: Failed to link org/jboss/as/jpa/hibernate3/HibernateAnnotationScanner (Module "org.jboss.as.jpa.hibernate:3" from local module loader @12c7568 (roots: /opt/Avaya/jboss-as-7.0.1.Final/modules))

                        at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:401)

                        at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:261)

                        at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:76)

                        at org.jboss.modules.Module.loadModuleClass(Module.java:588)

                        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:183)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:358)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:330)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:330)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:307)

                        at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:101)

                        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) [:1.6.0_11]

                        at org.jboss.as.jpa.hibernate3.HibernatePersistenceProviderAdaptor.beforeCreateContainerEntityManagerFactory(HibernatePersistenceProviderAdaptor.java:90)

                        at org.jboss.as.jpa.service.PersistenceUnitService.createContainerEntityManagerFactory(PersistenceUnitService.java:141)

                        at org.jboss.as.jpa.service.PersistenceUnitService.start(PersistenceUnitService.java:77)

                        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)

                        at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)

                        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_11]

                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_11]

                        at java.lang.Thread.run(Thread.java:619) [:1.6.0_11]

                Caused by: java.lang.NoClassDefFoundError: org/hibernate/ejb/packaging/Scanner

                        at java.lang.ClassLoader.defineClass1(Native Method) [:1.6.0_11]

                        at java.lang.ClassLoader.defineClass(ClassLoader.java:621) [:1.6.0_11]

                        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) [:1.6.0_11]

                        at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:397)

                        ... 18 more

                Caused by: java.lang.ClassNotFoundException: org.hibernate.ejb.packaging.Scanner from [Module "org.jboss.as.jpa.hibernate:3" from local module loader @12c7568 (roots: /opt/Avaya/jboss-as-7.0.1.Final/modules)]

                        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:191)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:358)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:330)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:330)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:330)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:307)

                        at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:101)

                        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) [:1.6.0_11]

                        ... 22 more

                 

                13:06:48,166 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC00001: Failed to start service jboss.persistenceunit."cs_cim_jpa.jar#SMGRPersistenceUnit": org.jboss.msc.service.StartException in service jboss.persistenceunit."cs_cim_jpa.jar#SMGRPersistenceUnit": Failed to start service

                        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1786)

                        at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)

                        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_11]

                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_11]

                        at java.lang.Thread.run(Thread.java:619) [:1.6.0_11]

                Caused by: java.lang.LinkageError: Failed to link org/jboss/as/jpa/hibernate3/HibernateAnnotationScanner (Module "org.jboss.as.jpa.hibernate:3" from local module loader @12c7568 (roots: /opt/Avaya/jboss-as-7.0.1.Final/modules))

                        at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:401)

                        at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:261)

                        at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:76)

                        at org.jboss.modules.Module.loadModuleClass(Module.java:588)

                        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:183)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:358)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:330)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:330)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:307)

                        at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:101)

                        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) [:1.6.0_11]

                        at org.jboss.as.jpa.hibernate3.HibernatePersistenceProviderAdaptor.beforeCreateContainerEntityManagerFactory(HibernatePersistenceProviderAdaptor.java:90)

                        at org.jboss.as.jpa.service.PersistenceUnitService.createContainerEntityManagerFactory(PersistenceUnitService.java:141)

                        at org.jboss.as.jpa.service.PersistenceUnitService.start(PersistenceUnitService.java:77)

                        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)

                        ... 4 more

                Caused by: java.lang.NoClassDefFoundError: org/hibernate/ejb/packaging/Scanner

                        at java.lang.ClassLoader.defineClass1(Native Method) [:1.6.0_11]

                        at java.lang.ClassLoader.defineClass(ClassLoader.java:621) [:1.6.0_11]

                        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) [:1.6.0_11]

                        at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:397)

                        ... 18 more

                Caused by: java.lang.ClassNotFoundException: org.hibernate.ejb.packaging.Scanner from [Module "org.jboss.as.jpa.hibernate:3" from local module loader @12c7568 (roots: /opt/Avaya/jboss-as-7.0.1.Final/modules)]

                        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:191)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:358)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:330)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:330)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:330)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:307)

                        at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:101)

                        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) [:1.6.0_11]

                        ... 22 more

                • 5. Re: Jboss AS 7 + Hibernate 4
                  smarlow

                  There are some notes in jira https://issues.jboss.org/browse/AS7-1583 about working with older (JPA 1.0) versions of Hibernate. 

                   

                  You also need to use a more recent build of AS7 (get the latest from http://community.jboss.org/thread/167590).

                   

                  The jira mentions some of the known restrictions, like the entity classes have to be specified in the persistence.xml.  This could in theory be improved, if you want to help contribute a patch that works better.  I got some basic tests working with Hibernate 3.3.x that write/read the database (in the AS7/testsuite/compat source folder).