Announcement Announcement Module
Collapse
No announcement yet.
Pitchfork and EJB3 CMT (via @TransactionAttribution) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pitchfork and EJB3 CMT (via @TransactionAttribution)

    I am trying to use pitchfork for EJB3 testing (ie: JPA, @EntityManager injection, @EJB injection and CMT transactions on @TransactionAttribute boundaries, etc.). JPA and EJB injection works great. However, EJB @TransactionAttribute annotations are not having any effect. (If I add a spring @Transactional annotation everything works well).

    I have the following Spring configuration:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/tx
          http://www.springframework.org/schema/tx/spring-tx.xsd">
    
    	<!-- Define the data source -->
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.SingleConnectionDataSource">
    		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
    		<property name="password" value="****" />
    		<property name="username" value="****" />
    		<property name="url" value="jdbc:mysql://****:3306/test" />
    		<property name="suppressClose" value="true" />
    	</bean>
    	
    	<!-- Configure the entity manager factory -->
    	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="dataSource" ref="dataSource" />
    		<property name="persistenceXmlLocation" value="classpath:META-INF/persistence-test.xml" />
    		<property name="persistenceUnitName" value="test" />
    		<property name="jpaVendorAdapter">
    			<!-- Hibernate -->
    			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    				<property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
    				<property name="generateDdl" value="false" />
    			</bean>
    		</property>
    	</bean>
    
    	<!-- we need a transaction manager for JPA -->
    	<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory" />
    	</bean>
    	
    	<!-- enable the configuration of transactional behavior based on annotations -->
    	<tx:annotation-driven transaction-manager="txManager"/>
    
    	<!-- EJB post processor -->
    	<bean class="org.springframework.jee.ejb.config.JeeBeanFactoryPostProcessor" />
    
    	<!-- Allows spring to scan all beans for persistence annotations -->
    	<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    	
    	<!-- Beans that we'd like JEE injection for -->
    	<bean class="com.test.TestServiceBean " />
    
    </beans>
    I have a simple EJB3 stateless bean like follows:

    Code:
    @Stateless
    public class TestServiceBean implements TestService {
    
        protected TestServiceBean () {
            super();
        }
        
        //@Transactional here works!
        @TransactionAttribute(TransactionAttributeType.REQUIRED)
        public void operation() {
            ...
        }
    
    }
    Is there anything wrong with my pitchfork configuration? Why isn't the EJB @TransactionAttribute being picked up?

    Interesting, I am getting debugging information that is suggesting the annotations are being at least considered:

    Code:
    [org.springframework.jee.inject.TransactionProcessor] adding txAttribute @javax.ejb.TransactionAttribute(value=REQUIRED) to method public void operation() ...
    Thanks.

  • #2
    Did you specify a ServiceEnvironment? I did some experimenting a while ago and this is what I used:

    Code:
      <bean class="org.springframework.jee.config.JeeBeanFactoryPostProcessor">
        <property name="serviceEnvironment">
          <bean class="org.springframework.jee.config.SimpleServiceEnvironment">
            <property name="transactionManager" ref="transactionManager"/>
          </bean>
        </property>
      </bean>

    Comment


    • #3
      Thank you very much, that works well.

      Comment

      Working...
      X