Hi,
It would seem I'm having trouble configuring spring to behaviour nicely with JTA and a CMT.
I'm attempting to call a spring managed bean through a SLSB.
e.g
My spring config looks like:Code:@Stateless(name="testApp.SpringTestSessionBean", mappedName="ejb/testApp/SpringTestSessionBean") @Interceptors(SpringBeanAutowiringInterceptor.class) public class SpringTestSessionBean implements SpringTestRemoteService { @Autowired private FacilityService facilityService; @TransactionAttribute(TransactionAttributeType.SUPPORTS) public List<Facility> getAllFacilities() { log.debug("Passing through SpringTestSessionBean to FacilityService."); try { List<Facility> facilities = facilityService.getAllFacilities(); return facilities; } catch(Exception e) { log.error("Failed to getAllFacilities.", e); throw new RuntimeException(e); } } } @Service public class FacilityServiceImpl implements FacilityService { private static Log log = LogFactory.getLog(FacilityServiceImpl.class); @Autowired private TestDAO dao; @Transactional(readOnly = true, propagation = Propagation.SUPPORTS, isolation = Isolation.SERIALIZABLE) public List<Facility> getAllFacilities() { log.debug("Accessing doa for facilities."); return dao.getFacilities(); } }
I have a Controller that calls the spring bean directly and correctly retrieves the results. However when I call it through the session bean I get the following exception:Code:<context:property-placeholder location="classpath:hibernate.properties"/> <!-- JNDI DataSource for JEE environments --> <jee:jndi-lookup id="dataSource" jndi-name="jdbc/scs"/> <!-- Transaction manager --> <tx:jta-transaction-manager /> <!-- Hibernate SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="packagesToScan" value="com.nag.test.domain"/> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop> <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.SunONETransactionManagerLookup</prop> <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop> </props> </property> </bean> <context:component-scan base-package="com.nag.test.dao"/> <!-- Find transaction management automatically on annotated classes. --> <tx:annotation-driven transaction-manager="transactionManager"/>
However that exception seems at odds with the transactionManager being successfully returned in the proceeding few lines of debug.Code:DEBUG com.nag.test.ejb.SpringTestSessionBean:42 - Creating instance of SpringTestSessionBean. DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory:240 - Returning cached instance of singleton bean 'serviceContext' DEBUG org.springframework.beans.factory.annotation.InjectionMetadata:59 - Found injected element on class [com.nag.test.ejb.SpringTestSessionBean]: AutowiredFieldElement for private com.nag.test.service.SpringTestService com.nag.test.ejb.SpringTestSessionBean.springTestService DEBUG org.springframework.beans.factory.annotation.InjectionMetadata:59 - Found injected element on class [com.nag.test.ejb.SpringTestSessionBean]: AutowiredFieldElement for private com.nag.test.service.FacilityService com.nag.test.ejb.SpringTestSessionBean.facilityService DEBUG org.springframework.beans.factory.annotation.InjectionMetadata:82 - Processing injected method of bean 'null': AutowiredFieldElement for private com.nag.test.service.SpringTestService com.nag.test.ejb.SpringTestSessionBean.springTestService DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory:240 - Returning cached instance of singleton bean 'springTest' DEBUG org.springframework.beans.factory.annotation.InjectionMetadata:82 - Processing injected method of bean 'null': AutowiredFieldElement for private com.nag.test.service.FacilityService com.nag.test.ejb.SpringTestSessionBean.facilityService DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory:240 - Returning cached instance of singleton bean 'facilityServiceImpl' DEBUG com.nag.test.ejb.SpringTestSessionBean:52 - Passing through SpringTestSessionBean to FacilityService. DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory:240 - Returning cached instance of singleton bean 'transactionManager' ERROR com.nag.test.ejb.SpringTestSessionBean:57 - Failed to getAllFacilities. java.lang.IllegalStateException: Operation not allowed. at com.sun.enterprise.distributedtx.UserTransactionImpl.checkUserTransactionMethodAccess(UserTransactionImpl.java:135) at com.sun.enterprise.distributedtx.UserTransactionImpl.getStatus(UserTransactionImpl.java:262) at org.springframework.transaction.jta.JtaTransactionManager.isExistingTransaction(JtaTransactionManager.java:795) at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:345) at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:336) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:102) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy143.getAllFacilities(Unknown Source)
I'm running this on Glassfish 2.1 and using Spring 3 RC2.
Thanks in advanced.


Reply With Quote