8 Replies Latest reply on Jun 12, 2012 10:02 AM by sam-user

    Hibernate 3.3.1 problems under JB 7

    sam-user

      I'm working on the migration of a Seam 2.1.1/Hibernate 3.3.1 application from JB5.1 to JB7 and the main problems I have are related to Hibernate and the incompatibility between it's versions (prior and after 3.5)

      I managed to deploy my application using the provided Hibernate module (ver.4.0.1) and for the most of the time it works fine. Until I try to save an entity in the DB. I have entities that have String ID columns and I get exception "Unknown integral data type for ids : java.lang.String" when an Id is generated via SequenceGenerator. I know this is a Hibernate issue but if anyone has any solutions for this -please share your experience.

      I also tried using the original version of Hibernate (3.3.1) following the advices in the guide "How do I migrate my application from AS5/As6 to AS7". And I stumbled across a different problem: I get the exceptions below:

       

      14:40:12,063 DEBUG [org.jboss.as.jpa] (MSC service thread 1-4) added (default provider) org.hibernate dependency to XXX.war (since 1 PU(s) didn't specify jboss.as.jpa.providerModule)
      14:40:12,063 DEBUG [org.jboss.as.jpa] (MSC service thread 1-4) added org.hibernate.envers:main dependency to XXX.war
      14:40:12,063 DEBUG [org.jboss.as.jpa] (MSC service thread 1-4) added org.hibernate:main dependency to XXX.war
      
      
            
      14:40:13,048 TRACE [org.jboss.as.jpa] (MSC service thread 1-3) adding 'vfs:/C:/Apps/jboss-as-7.1.1.Final/bin/content/XXX.war/WEB-INF/lib/xmlpublic.jar/' to annotation index map
      14:40:13,063 DEBUG [org.jboss.as.jpa] (MSC service thread 1-3) loaded persistence provider adapter org.jboss.as.jpa.hibernate:4
      14:40:13,063 TRACE [org.jboss.as.jpa] (MSC service thread 1-3) returning global (module) Persistence Provider org.hibernate.ejb.HibernatePersistence
      14:40:13,063 TRACE [org.jboss.as.jpa] (MSC service thread 1-3) lookup provider checking provider version (4.0.1.Final)
      
      
      14:40:13,188 TRACE [org.jboss.as.jpa] (MSC service thread 1-3) added PersistenceUnitService for 'service jboss.persistenceunit."XXX.war#XXX"'.  PU is ready for injector action.
      14:40:13,563 INFO  [org.jboss.as.jpa] (MSC service thread 1-6) JBAS011402: Starting Persistence Unit Service 'XXX.war#XXX'
      14:40:13,673 INFO  [org.hibernate.annotations.common.Version] (MSC service thread 1-6) HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
      14:40:13,673 INFO  [org.hibernate.Version] (MSC service thread 1-6) HHH000412: Hibernate Core {4.0.1.Final}
      14:40:13,688 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-6) HHH000206: hibernate.properties not found
      14:40:13,688 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-6) HHH000021: Bytecode provider name : javassist
      14:40:13,704 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-6) HHH000204: Processing PersistenceUnitInfo [
                name: XXX
                ...]
      
            
      
      14:40:13,876 TRACE [org.jboss.as.jpa] (MSC service thread 1-6) getPackagesInJar found package package com.xxx.yyy.xxx.action
      14:40:14,438 INFO  [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-6) HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
      14:40:14,438 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-6) MSC00001: Failed to start service jboss.persistenceunit."XXX.war#XXX": org.jboss.msc.service.StartException in service jboss.persistenceunit."xxx.war#xxx": Failed to start service
                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_10-rc2]
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_10-rc2]
                at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_10-rc2]
      Caused by: javax.persistence.PersistenceException: [PersistenceUnit: XXX] Unable to build EntityManagerFactory
                at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
                at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)
                at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
                at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)
                at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)
                at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                ... 3 more
      Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]
                at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:187)
                at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:150)
                at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
                at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:234)
                at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:91)
                at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
                at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
                at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
                at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
                at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2270)
                at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2266)
                at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1735)
                at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84)
                at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
                ... 9 more
      Caused by: org.hibernate.HibernateException: Could not instantiate connection provider [org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider]
                at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:190)
                at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:112)
                at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:54)
                at org.hibernate.service.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:69)
                at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:177)
                ... 22 more
      Caused by: java.lang.ClassCastException: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider cannot be cast to org.hibernate.service.jdbc.connections.spi.ConnectionProvider
                at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:187)
                ... 26 more
      
      

       

      Here's my jboss-deployment-structure.xml file

       

      <jboss-deployment-structure>
        <deployment>
          <exclusions> 
            <module name="javax.faces.api" slot="main"/>
            <module name="com.sun.jsf-impl" slot="main"/>    
            <module name="org.hibernate" slot="main"/>    
            <module name="org.hibernate.validator" slot="main" />   
          </exclusions>
          <dependencies>
            <module name="org.dom4j"/>
            <module name="org.apache.log4j"/>
            <module name="org.apache.commons.collections"/>
            <module name="javax.faces.api" slot="1.2"/>
            <module name="com.sun.jsf-impl" slot="1.2"/>
          </dependencies>
        </deployment>
      </jboss-deployment-structure>
      
      
      

       

       

      And here's my persistence.xml

       

      <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="XXX" transaction-type="JTA">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>java:jboss/datasources/XXXDatasource</jta-data-source>
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
               <property name="hibernate.hbm2ddl.auto" value="validate"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="jboss.entity.manager.factory.jndi.name" value="java:/XXXEntityManagerFactory"/>
      
      
            </properties>
         </persistence-unit>
          
      </persistence>
      
      

       

      I have copied in WEb-INF/lib the following files (ver.3.3.1):

       

      hibernate-core.jar

      hibernate-annotations.jar

      hibernate-commons-annotations.jar

      hibernate-entitymanager.jar

      hibernate-validator.jar

       

       

      I can also see at the beginning of the log file that although I excluded Hibernate 4.0.1 from the deployment it's still being deployed.

       

      Could anyone tell me what am I missing or doing wrong?

      Thanks.

        • 1. Re: Hibernate 3.3.1 problems under JB 7
          smarlow

          We improved support for packaging persistence providers with the application but it sounds like that is not help you.  Perhaps your not on the latest AS7 release.  Which version of AS7 are you using?  Try using either AS 7.1.1 or the nightly AS7 build.

           

          If that isn't enough, enable TRACE logging for org.hibernate and org.jboss.as.jpa (see instructions here).  Lets us know and attach the as7/standalone/log/server.log (after deploying your app with TRACE logging enabled).

           

          Scott

          • 2. Re: Hibernate 3.3.1 problems under JB 7
            sam-user

            Scott, I forgot to mention that I am on JBoss 7.1.1.

            Here's the full server.log.

            Thanks.

            • 3. Re: Hibernate 3.3.1 problems under JB 7
              smarlow

              Try adding another persistence.xml property to the current ones:

               

              <property name="jboss.as.jpa.providerModule" value="hibernate3-bundled"/>

               

              Let us know if that helps (post the updated server.log if not).  For other (future) questions about application issues on AS 7, please open a discussion here

               

              Scott

              • 4. Re: Hibernate 3.3.1 problems under JB 7
                sam-user

                That made it worse. I just want to point out that all the hibernate jars are copied to my application WEB-INF\lib folder.

                I attached the server.log file

                • 5. Re: Hibernate 3.3.1 problems under JB 7
                  smarlow

                  You are getting further but hitting a bug that crept into 7.1.1 (the Hibernate-Infinispan references).  Its fixed in the AS7 nightly build

                   

                  Also, does your application expect to lookup the "java:/XXXXEntityManagerFactory"?  The jndi name is not valid under AS7 and will need to change.  Might be easier to use a @PersistenceUnit annotation instead to access the EntityManagerFactory that is created for the persistence.xml persistence unit(s) during deployment.

                   

                  Another issue is that you are using a JPA 1.0 persistence provider (that isn't causing problems for you but that is pretty old).  You might want to upgrade to Hibernate 3.6.10 or 4.1.2 at some point.

                  1 of 1 people found this helpful
                  • 6. Re: Hibernate 3.3.1 problems under JB 7
                    sam-user

                    Scott,

                    Unfortunatelly upgrading to higher version of hibernate doesn't seem to be an option for my case.

                    Anyway, I now installed the lates nightly build JB AS 7.2.0.Alpha1-SNAPSHOT and I think I got a bit further. Although the application seem to have deployed it doesn't actually work. And the reson seem to be a missing hibernate Scanner class. I attached the log file. Any idea how to jump this next hurdle?

                    Thanks.

                    • 7. Re: Hibernate 3.3.1 problems under JB 7
                      smarlow

                      I believe that you can ignore the missing "Scanner" class error.  Since Hibernate 3.3.1 doesn't have the Hibernate Scanner class (you will have to manually add each entity class to the persistence.xml instead or upgrade to a more recent Hibernate 3.6.x/4.x release). 

                      1 of 1 people found this helpful
                      • 8. Re: Hibernate 3.3.1 problems under JB 7
                        sam-user

                        Scott,

                        Thanks for your help. Following your advices I managed to successfully migrate my application to JB7. I did have to use JB 7.2.x, though.