1
votes

I work on a multi-module maven application and the weblogic is already in prod. The stack is :

Tomcat 8.5

PostGre 9.6

Hibernate 4.3.8

Spring 4.1.5

Spring Security 3.2.6

Spring Struts 3.2.13

Primes Faces 5.1

I begin to migrate with the creation of a JNDI DataSource in server.xml and a resource link in META-INF/context.xml (we move the DB from DB2 to PostGre) but i got an exception :

Caused by: java.lang.IllegalStateException: No JTA UserTransaction available - specify either 'userTransaction' or 'userTransactionName' or 'transactionManager' or 'transactionManagerName'

My application is on xml config and i think the error occur beacause JTA implentation was delegate to weblogic in the old version :

DataSourceContext.xml

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

http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:comp/env/jdbc/mydatasourcename" />
</bean>

<bean id="hibernateProperties"
    class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="properties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
            <prop key="hibernate.query.substitutions">true=1 false=0</prop>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.max_fetch_depth">1</prop>
            <prop key="hibernate.default_schema">defaultschemaname</prop>
            <!-- How to find the Transaction -->
            <prop key="hibernate.transaction.factory_class">org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory
            </prop>

            <!-- How to produce transaction -->

            **<prop key="hibernate.transaction.jta.platform">org.hibernate.engine.transaction.jta.platform.internal.WeblogicJtaPlatform
            </prop>**

            <!-- Session context with JTA -->
            <prop key="current_session_context_class">jta</prop>
        </props>
    </property>
</bean>

My Tomcat DataSource :

<GlobalNamingResources>
<!-- Editable user database that can also be used by
     UserDatabaseRealm to authenticate users
-->
    <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" readonly="true" type="org.apache.catalina.UserDatabase"/>
    <Resource auth="Container" driverClassName="org.postgresql.Driver" 
         maxIdle="10"
         maxTotal="20"
         maxWaitMillis="10000" 
         name="jdbc/*****" 
         password="*****" 
         type="javax.sql.DataSource" 
         url="jdbc:postgresql://********:5432/****" 
         username="****"/>  
</GlobalNamingResources>

Hibernate Config applicationContextDAO.xml :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">


    <bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="packagesToScan">
            <list>
              <value>package.name</value>
            </list>
        </property> 
        <property name="annotatedPackages">
            <list>
                <value>package.name</value>
            </list>
        </property>
        <property name="hibernateProperties" ref="hibernateProperties" />
        <property name="dataSource" ref="dataSource" />
    </bean>

    <bean id="saveHibernateListener" class="package.name.hibernateListener.SaveHibernateListener"/>

    <bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
        <property name="propertyEditorRegistrars">
            <list>
                <bean class="package.name.CustomDateEditorRegistrar"/>
            </list>
        </property>
    </bean>

<!-- Template hibernate injecté dans chaque persisteur -->
    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate">
        <property name="sessionFactory" ref="mySessionFactory" />
    </bean>
</beans>

Facade module applicationContext-transaction.xml

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

http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

<tx:advice id="txAdvice">
    <tx:attributes>
        <tx:method name="get*" propagation="REQUIRED" read-only="true"
            rollback-for="ExceptionWork" />
        <tx:method name="*" propagation="REQUIRED" rollback-for="MessageException" />
    </tx:attributes>
</tx:advice>

<aop:config>
    <aop:pointcut id="ivaFacadePointcut"
        expression="execution(* package.name..*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="FacadePointcut" />
</aop:config>

<aop:aspectj-autoproxy proxy-target-class="true"/>

<tx:jta-transaction-manager />
<tx:annotation-driven/>


I think i have to replace this prop in DataSourceContext.xml : org.hibernate.engine.transaction.jta.platform.internal.WeblogicJtaPlatform ?

An existing clean solution to implement a Transaction Manager in tomcat 8.5? Or a standalone Transaction Manager?

I'm confused about all solution i already found(old version of hibernate or depreciated implementation of JTA)...if someone can enlight me i will appreciate :)

1

1 Answers

0
votes

While Weblogic is a full Application Server, Tomcat is in the hand only a web container. Due to that you need to close a few gaps between those two.

A transaction manager is one of them. Weblogic will "automatically" add one for you while Tomcat doesn't have the ability to do so.

If you use something like the snippet below you should be able to get past this problem.

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>