1 Reply Latest reply on Jan 10, 2013 7:25 AM by marvin182

    Jboss 7 - Spring - using Jboss Entity-/TransactionManager

    marvin182

      Hi there!

       

      Im using: Jboss 7.1.1, Hibernate 3.6.9, Spring 3.0.1.

       

      Currently I have following configuration which works great (but user want to switch from 'org.springframework.orm.jpa.JpaTransactionManager' to jboss transaction management):

       

      applicationContext.xml (spring) snippet:

       

      <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="my_pu" />
        <property name="dataSource" ref="dataSource" />
        <property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml" />
        <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="databasePlatform" value="org.hibernate.dialect.SQLServerDialect" />
        <property name="showSql" value="false" />
        <property name="generateDdl" value="false" />
        </bean>
        </property>
       </bean>
      
      
      <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
        <property name="dataSource" ref="dataSource" />
       </bean>
      
      
      <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> 
                          <property name="jndiName" value="${database.jndi.path}" />
      </bean>
      
      
      

       

      persistence.xml snippet:

       

       

       <persistence-unit name="my_pu" transaction-type="RESOURCE_LOCAL">
      
      
        <properties>
        <property name="jboss.as.jpa.managed" value="false" />
         <property name="hibernate.dialect"
            value="org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect" />
        </properties>
       </persistence-unit>
      </persistence>
      
      

       

      Someone could tell me how to switch to jboss transaction management?

       

      Already tried out several configurations but nothings works..

        • 1. Re: Jboss 7 - Spring - using Jboss Entity-/TransactionManager
          marvin182

          What I did so far:

           

          persitence.xml:

          <?xml version="1.0" encoding="UTF-8" standalone="no"?>
          <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
                    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
                    <persistence-unit name="my_pu" transaction-type="JTA">
          
           <!--<provider>org.hibernate.ejb.HibernatePersistence</provider>-->
           <jta-data-source>java:jboss/datasources/my_ds</jta-data-source>
          
          
                              <properties>
                                        <!--<property name="hibernate.transaction.manager_lookup_class"
                          value="org.hibernate.transaction.JBossTransactionManagerLookup" />-->
          
          
                                        <property name="hibernate.dialect"
                                                  value="org.hibernate.dialect.SQLServerDialect" />
          
                                        <!--
                                        <property name="jboss.as.jpa.providerModule" value="hibernate3-bundled" />
                                        <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory" />
                                        -->
          
                                        <property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/myEntityManagerFactory" />
                              </properties>
                    </persistence-unit>
          </persistence>
          
          

           

          applicationContext.xml:

           

              <!--<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                  <property name="persistenceUnitName" value="my_pu" />
              </bean>
          
          
              <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
                  <property name="transactionManagerName" value="java:/TransactionManager" />
              </bean>-->
          
          
          
          
          
          
          
          <jee:jndi-lookup id="entityManagerFactory" jndi-name="java:jboss/myEntityManagerFactory" />
          
                    <!--
                    <tx:jta-transaction-manager/> -->
          
          
          
          
                    <!-- JBoss -->
                    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> 
                              <property name="jndiName" value="${database.jndi.path}" />
                    </bean>
          
          
          
          
          
          
          
          
          <jee:jndi-lookup id="entityManagerFactory" jndi-name="java:jboss/myEntityManagerFactory" />
          
                    <!--
                    <tx:jta-transaction-manager/> -->
          
          
          
          
                    <!-- JBoss -->
                    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> 
                              <property name="jndiName" value="${database.jndi.path}" />
                    </bean>
          
          

           

          Stacktrace:

           

          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
          
          

           

           

          problem with hibernate 3 which is within my .war and hibernate 4 from jboss?