Announcement Announcement Module
Collapse
No announcement yet.
@Transactional / JPA / JTA / JBoss 5.1.0 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Transactional / JPA / JTA / JBoss 5.1.0

    Hi, I don't get the transaction work with my setup:

    My repository bean:

    Code:
    @Transactional
    public class UserRepositoryBean implements UserRepository {
    	
    @PersistenceContext(unitName = "blabla")private EntityManager entityManager;
    
    public IBewirtschafterUser updateBewirtschafterUser(Context ctx, IBewirtschafterUser bewUser) {
        .....
    }
    My spring config:
    Code:
    <bean id="entityManagerFactory"
    		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="persistenceUnitName" value="blabla" />
    		<property name="jpaVendorAdapter">
    			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    				<!-- <property name="showSql" value="true" /> -->
    				<property name="databasePlatform" value="org.hibernate.dialect.OracleDialect" />
    			</bean>
    		</property>
    	</bean>
    
    	<tx:annotation-driven transaction-manager="txManager" />
    
    	<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory" />
    	</bean>
    
    	<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    		<property name="jndiName" value="java:blablaDS" />
    	</bean>
    My persistence.xml:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- 
    <persistence version="2.0"
    	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_2_0.xsd">
     -->
    <persistence version="2.0"
    	xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    	<persistence-unit name="blabla" transaction-type="JTA">
    		<provider>org.hibernate.ejb.HibernatePersistence</provider>
    		<jta-data-source>java:/blablaDS</jta-data-source>
    		<class>blabla.persistence.entity.blabla</class>
    		<properties>
    			<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
    			<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
    			<property name="hibernate.hbm2ddl.auto" value="read-write" />
                <property name="hibernate.show_sql" value="true" />
                <property name="hibernate.format_sql" value="true" />
                <property name="hibernate.use_sql_comments" value="true" />
    		</properties>
    	</persistence-unit>
    </persistence>
    It looks like spring don't attaches a transaction to the method call: updateBewirtschafterUser.
    When I use
    Code:
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    instead of
    Code:
    @Transactional
    then it works.

    Can anybody explain whats going on?

  • #2
    More Tests

    Ok I tried the following things:
    1. Transactional on method: It changed nothing, when I moved the Transactional onto the method, same behaviour, no transaction
    2. propagation=REQUIRED on Transactional, when I added the propagation=REQUIRED, same behaviour, no transaction
    3. flush after merge: Of course this worked, the record was inserted, but this was just a check if something completly is wrong

    Comment


    • #3
      Ok, when I change the Transactional to TransactionAttribute then it works.

      Code:
      @TransactionAttribute(TransactionAttributeType.REQUIRED)
      public class UserRepositoryBean implements UserRepository
      I really don't understand whats going on, its pure trial and error

      Comment


      • #4
        Forgot to mention which spring version I use:
        Spring: 3.1.2

        Comment

        Working...
        X