1 Reply Latest reply on Sep 13, 2012 3:56 AM by yunshi

    InjectedDataSourceConnectionProvider  ClassCastException in using Hibernate 3.5 in JBoss AS7

    yunshi

      Hi all,

       

      I am doing the migration jboss4.2.3 to jboss7.

       

      In jboss4.2.3, I have Hibernate3.2.  I would like to use Hibernate 3.5 (or Hibernate 3.3 even better )  instead of Hibernate 4 for the reason of Seam2, who is not at all compatible with hibernate4.

       

       

      I am

       

      - following the migration guide here : https://docs.jboss.org/author/display/AS7/Developer+Guide#DeveloperGuide-ConfigurethedatasourceforHibernateorJPA to define my Jboss3 module.

      - also read this : http://badr-elhouari.blogspot.fr/2011/10/how-to-use-hibernate-3-as-jpa-provider.html.

      - read all the posts in the forum about Hibernate3.3 + jboss7 and Hibernate3.5 + jboss7.

      - tried with hibernate 3.3 jars

      - tried with hibernate 3.5 jars

      - tried with nightly build jboss7

       

      But I always have the InjectedDataSourceConnectionProvider  ClassCastException when I start up the server with my ejb-jar deployed.

       

      Does anyone have an idea pl ? or share some experiences ?

       

      Here is the exception trace :

       

      09:45:40,759 INFO  [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-2) HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider

      09:45:40,763 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.persistenceunit."persistence-gincomp-impl_2.0.25-SNAPSHOT.jar#gincomp-unit": org.jboss.msc.service.StartException in service jboss.persistenceunit."persistence-gincomp-impl_2.0.25-SNAPSHOT.jar#gincomp-unit": 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.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_05]

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_05]

              at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_05]

      Caused by: javax.persistence.PersistenceException: [PersistenceUnit: gincomp-unit] 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

       

       

      My Hibernate 3.5 customerized module.xml :

       

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

          <resources>

       

            <resource-root path="jpa-api-2.0.Beta2.jar"/>    

       

              <resource-root path="hibernate-validator-legacy-4.0.2.GA.jar"/>

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

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

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

          <!--

           <resource-root path="hibernate-jpamodelgen-1.0.0.Final.jar"/>

          -->

             <resource-root path="validation-api-1.0.0.GA.jar"/>

              <resource-root path="javassist-3.12.0.GA.jar"/>

              <resource-root path="antlr-2.7.6.jar"/> 

              <resource-root path="commons-collections-3.1.jar"/> 

              <!-- Insert resources here -->

          </resources>

       

          <dependencies>

             <module name="org.jboss.as.jpa.hibernate" slot="3"/>

              <module name="asm.asm"/>

              <module name="javax.api"/>

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

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

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

              <module name="org.infinispan"/>

              <module name="org.javassist"/>

              <module name="org.slf4j"/>

           <module name="org.dom4j"/>

          </dependencies>

       

      </module>

       

       

      In the persistence.xml of my ejb-jar I have

      <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-unit" transaction-type="JTA">

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

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

              <properties>

                <property name="hibernate.ejb.cfgfile" value="/META-INF/hibernate-xxx.cfg.xml"/>

                <property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/EntityManagerFactories/XXX"/>

                <property name="hibernate.session_factory_name" value="java:jboss/hibernate/SessionFactoryWeb"/>

       

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

       

                </properties>

          </persistence-unit>

      </persistence>

       

      Here is the jboss-deployment-structure of the ejb-jar


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

       

      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">

        <deployment>

            <exclusions>

              <module name="javax.faces.api" slot="main"/>

              <module name="com.sun.jsf-impl" slot="main"/>

              <module name="org.hibernate" />  

              <module name="org.javassist"/>

               </exclusions>

            <dependencies>

                   <module name="org.hibernate" slot="3.5" export="true" />

            </dependencies>

        </deployment>

       

         

      </jboss-deployment-structure>