Announcement Announcement Module
No announcement yet.
Spring + Hibernate + JOTM + MySQL = threads are not correctly closed Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring + Hibernate + JOTM + MySQL = threads are not correctly closed

    Hi community,

    I'm new on developing and I have being configuring my application based on your help since few months ago.

    Everything seems to be working fine with JPA, until my application start asking for userTransaction support.

    I found that I should add JTA support in my build path and everything starts working again until I try to publish my application using Tomcat 6.0 over LiveCycleDataService from Adobe.

    It seems that JTA jars were generating some incompatilibility problems with JOTM jars provided in Tomcat, so I started looking after comments and suggestions in the forum and I was able to make it work... but - and there is always a but in this project - I'm facing a basic problem... my main end but there are still some threads that keep runnig until I terminate the excecution...

    I debug my app and found nothing... no errors in log4J, no alerts... but I'm sure that something is wrong in my Spring configuration files...

    If anyone can help me to find out what is going on here it would really help me to start developing my system...

    Next I'm leaving the spring-context.xml I'm using, and the persistence.xml file:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns=""
      <!-- enables interpretation of the @Required annotation to ensure that dependency injection actually occures -->
      <bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>  
      <!-- enables interpretation of the @PersistenceUnit/@PersistenceContext annotations providing convenient
           access to EntityManagerFactory/EntityManager -->
      <bean class=""/>
      <!-- first XA data source -->
      <bean id="bdbInnerDataSource" class="org.enhydra.jdbc.standard.StandardXADataSource">
        <property name="driverName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/medicalcare"/>
      <!-- first XA data source pool -->
      <bean id="bdbDataSource" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource">
        <property name="transactionManager" ref="jotm"/>
        <property name="dataSource" ref="bdbInnerDataSource"/>
        <property name="user" value="root"/>
        <property name="password" value="root"/>
        <property name="maxSize" value="4"/>
      <!-- second XA data source 
      <bean id="bpeInnerDataSource" class="org.enhydra.jdbc.standard.StandardXADataSource">
        <property name="transactionManager" ref="jotm"/>
        <property name="driverName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/medicalcare"/>
        <property name="user" value="root"/>
        <property name="password" value="root"/>
      <!-- second XA data source pool 
      <bean id="bpeDataSource" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource">
        <property name="transactionManager" ref="jotm"/>
        <property name="dataSource" ref="bpeInnerDataSource"/>
        <property name="user" value="root"/>
        <property name="password" value="root"/>
        <property name="maxSize" value="4"/>
      <!-- required cos the standalone JOTM transaction manager is not autodetected by the
           JtaTransactionManager cos it requires a static accessor method -->
      <bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>
      <!-- supplying the JotmFactoryBean merely to the userTransaction property cos JtaTransactionManager
           autodetects that the object returned by the JotmFactoryBean implements both the
           UserTransaction and the TransactionManager interface-->
      <bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="userTransaction" ref="jotm"/>
        <property name="allowCustomIsolationLevels" value="true"/>
      <!-- settings previously specified in the persistence.xml JPA configuration file are now defined with the
           LocalContainerEntityManagerFactoryBean configuration -->  
      <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">    
        <!-- reference to the XA datasource -->
        <property name="dataSource" ref="bdbDataSource"/>
        <!-- specify Hibernate as the the JPA provider -->
        <property name="jpaVendorAdapter">
          <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="true"/>
            <property name="generateDdl" value="false"/>
            <property name="database" value="MYSQL"/>
            <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect"/>
        <!-- configure Hibernate to participate in JTA transactions using the JOTM transaction manager and
             specify further Hibernate specific configuration properties -->
        <property name="jpaPropertyMap">
         	 <entry key="hibernate.connection.release_mode" 
            <entry key="hibernate.transaction.manager_lookup_class"
            <entry key="hibernate.transaction.flush_before_completion"
            <entry key="hibernate.transaction.auto_close_session"
            <entry key="hibernate.current_session_context_class"
            <entry key="hibernate.connection.release_mode"
        <!-- specify that the Hibernate JPA dialect should be used, probably not necessary since 
             HibernateJpaVendorAdapter will most likely set this property -->
        <property name="jpaDialect">
          <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
        <!-- custom implementation to enrich the PersistenceUnitInfo read from the persistence.xml
             JPA configuration file with the JTA datasource. specifying the JTA datasource directly in
             the Spring configuration file has the advantage that we can use a direct reference to the
             datasource instead of using a JNDI name as requied by the jta-data-source setting in the
             persistence.xml file -->
        <property name="persistenceUnitPostProcessors">
          <bean class="ar.medicalcare.persistence.JtaPersistenceUnitPostProcessor">
            <property name="jtaDataSource" ref="bdbDataSource"/>		
     	<!-- Repositories -->
    	<bean id="patientRepository"
    		class="ar.medicalcare.persistence.PatientRepositoryJPA" />
    	<bean id="employeeRepository"
    		class="ar.medicalcare.persistence.EmployeeRepositoryJPA" />
      <!-- enables interpretation of the @Transactional annotation for declerative transaction managment
           using the specified JtaTransactionManager -->
      <tx:annotation-driven transaction-manager="jtaTransactionManager" proxy-target-class="false"/>
      <!-- enables interpretation of the @Configurable annotation for domain object dependency injection -->

    <?xml version="1.0" encoding="UTF-8"?>
    <persistence xmlns=""
      <!-- transaction type set to JTA, transaction suspension and XA supported -->
      <persistence-unit name="SpringConfiguredPersistenceUnit" transaction-type="JTA"/>
    Many thanks for any kind of suggestions/comment you can give me.