Announcement Announcement Module
Collapse
No announcement yet.
JTATransactionManager Not Committing To Database Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JTATransactionManager Not Committing To Database

    Hi
    I will be working with a database and with a JMS queue so I decided to use JTATransactionManager (multiple resources).
    I am using Spring Framework 3.2.3.RELEASE
    Hibernate 4.2.1.Final
    Glassfish 3.1.2.2

    With JTATransactionManager nothing is committed to db.I tried JPATransactionManager it works fine.I don't get any exceptions with JTATransactionManager.Any idea what I am doing wrong?Thanks.

    This is a piece of jpa config file
    Code:
    <jee:jndi-lookup id="dataSource" jndi-name="Test" />
    
    <bean id="entityManagerFactory"
       class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
           p:packagesToScan="com.pinkshield.jpaTest.domain" 
           p:dataSource-ref="dataSource"
           p:jpaPropertyMap-ref="jpaPropertyMap" 
           p:jpaVendorAdapter-ref="hibernateVendor" />
    
    
    <util:map id="jpaPropertyMap">
        <entry key="hibernate.hbm2ddl.auto" value="validate" />
        <entry key="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
        <entry key="transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory" />
        <entry key="transaction.manager_lookup_class"
            value="org.hibernate.transaction.SunONETransactionManagerLookup" />
    </util:map>
    
    <bean id="hibernateVendor"
        class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
        p:showSql="true" />
    
    <tx:jta-transaction-manager />
    
    <tx:annotation-driven/>
    
    <context:component-scan base-package="com.pinkshield.jpaTest" />
    This is my Generic Dao for JPA
    Code:
    package com.pinkshield.jpaTest;
    
    import java.util.List;
    
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    
    public class GenericDaoJpa<T> implements GenericDao<T> 
    {
    
    private Class<T> queryClass;
    protected EntityManager entityManager;
    
    @PersistenceContext
    public void setEntityManager(EntityManager entityManager) 
    {
        this.entityManager = entityManager;
    }   
    
    public GenericDaoJpa(Class<T> queryClass) 
    {
        super();
        this.queryClass = queryClass;
    }
    
    public T getNewInstance() 
    {
        try 
        {
            return getQueryClass().newInstance();
        } 
        catch (InstantiationException e) 
        {
            throw new RuntimeException("Error creating new instance of : " + getQueryClass().getName(), e);
        } 
        catch (IllegalAccessException e) 
        {
            throw new RuntimeException("Error creating new instance of : " + getQueryClass().getName(), e);
        }
    }
    
    public Class<T> getQueryClass() 
    {
        return queryClass;
    }    
    
    public T get(Long id) 
    {
        if (id == null) 
        {
            return null;
        } 
        else 
        {
            return entityManager.find(queryClass, id);
        }
    }
    
    @SuppressWarnings("unchecked")
    public List<T> getAll() 
    {
        return entityManager.createQuery("select o from " + queryClass.getName() + " o").getResultList();
    }
    
    public void save(T object) 
    {
        entityManager.persist(object);
    }
    
    public void update(T object) 
    {
        entityManager.merge(object);
    }
    
    public void delete(T object) 
    {
        entityManager.remove(entityManager.merge(object));
    }
    }
    This is UserDao
    Code:
    @Repository
    public class UserDao extends GenericDaoJpa<User> 
    {
    public UserDao() 
    {
        super(User.class);
    }
    }
    And this is my service code

    Code:
     @Service
     public class UserServiceImpl implements IUserService{
    
    @Autowired UserDao userDao;
    
    @Override
    @Transactional
    public void saveUser(String name, String lastName)
      { 
        User user=new User();
        user.setLastName(lastName);
        user.setName(name);
    
        userDao.save(user);
       }
     }

  • #2
    Instead of the datasource set the jtaDatasource... Next to that instead of transaction.factory_class and transaction.manager_lookup_class use the hibernate.transaction.jta.platform property.

    Comment


    • #3
      Originally posted by Marten Deinum View Post
      Instead of the datasource set the jtaDatasource... Next to that instead of transaction.factory_class and transaction.manager_lookup_class use the hibernate.transaction.jta.platform property.
      Marten thanks for your reply I updated my config file as you suggested but still it is not working.Here is my updated config file.

      Code:
      	<jee:jndi-lookup id="dataSource" jndi-name="Test" />
      
      	<bean id="entityManagerFactory"
      		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
      		p:packagesToScan="com.thinkshield.jpaTest.domain" 
      		p:jtaDataSource-ref="dataSource"
      		p:jpaPropertyMap-ref="jpaPropertyMap" 
      		p:jpaVendorAdapter-ref="hibernateVendor" />
      
      
      	<util:map id="jpaPropertyMap">
      		<entry key="hibernate.hbm2ddl.auto" value="validate" />
      		<entry key="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
      	    <entry key="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform"/>
      	</util:map>
      
      	<bean id="hibernateVendor"
      		class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
      		p:showSql="true" />
      
      	<context:annotation-config/>
      	
      	<tx:jta-transaction-manager/> 
      	
      	<context:component-scan base-package="com.pinkshield.jpaTest" />
      And I found this in my log file "hibernate.properties not found" can this be related to my problem?
      Thanks

      Comment


      • #4
        Originally posted by emre123
        And I found this in my log file "hibernate.properties not found" can this be related to my problem?
        No this is, next to hibernate.xml, one of the default configuration files checked by hibernate.

        If you have a persistence.xml file make sure you have set the transaction-type to JTA.

        Comment


        • #5
          Originally posted by Marten Deinum View Post
          No this is, next to hibernate.xml, one of the default configuration files checked by hibernate.

          If you have a persistence.xml file make sure you have set the transaction-type to JTA.
          Marten

          No I am not using persistence.xml I wanted to configure everything with spring way. Any other advice you could give me for solving this problem?

          Thanks

          Comment

          Working...
          X