2011-03-07 3 views
2

봄 @Transactional - 다음 스키마에서 javax.persistence.TransactionRequiredException

컨트롤러 -> 서비스 -> DAO 난 내가() 호출 내 UserService.fooFunction에

@Transactional 서비스 운영을 위해 노력하고있어 마지막 dao.update (E)에

Entity e = dao.find(key) 
e.setProperty(something) 
dao.update(e) 

em.flush() //EntityManager obtained by @PersistenceContext annotation (injected by spring IoC) 

존재() 플러시 드로우 요구하는 persistenceException : 내가 잘못 한 일을 나는 아이디어가 부족 해요

javax.persistence.TransactionRequiredException No externally managed transaction is currently active for this thread 
    at org.eclipse.persistence.internal.jpa.transaction.JTATransactionWrapper.throwCheckTransactionFailedException(JTATransactionWrapper.java:86) 

는, 어떤 도움을 주시면 감사하겠습니다 :) 당신은 아래에있는 내 구성의 덩어리를 찾을 수 있습니다

:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
    <property name="dataSource" ref="dataSource"/> 
    <property name="persistenceUnitName" value="myPU" /> 
    <property name="jpaVendorAdapter"> 
     <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter" id="eclipselinkVendorAdapter"> 
     .. 
     </bean> 
    </property> 

</bean> 

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> 

</bean> 
<tx:annotation-driven transaction-manager="transactionManager"/> 

AOP 부 :

<aop:config> 

    <aop:pointcut id="userServiceOperation" 
     expression="execution(* org.mypackage.UserServiceImpl.*(..))"/> 

    <aop:advisor pointcut-ref="userServiceOperation" advice-ref="txUserServiceAdvice"/> 

</aop:config> 

<tx:advice id="txUserServiceAdvice"> 
    <tx:attributes> 
     <tx:method name="get*" read-only="true" propagation="REQUIRES_NEW"/> 
     <tx:method name="update*" read-only="false" propagation="REQUIRES_NEW"/> 
     <tx:method name="*" propagation="REQUIRES_NEW"/> 
    </tx:attributes> 
</tx:advice> 

어떠한 트랜잭션 주석이 존재하지 않는다. . 주석 중심은 @Transactional 것이에 정의 된 같은 애플리케이션 컨텍스트 내에서 콩에 보이는 : 내 봄 응용 프로그램을 배포 할 때 하나

[<date>] DEBUG support.DefaultListableBeanFactory: Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor' 
[<date>] DEBUG interceptor.NameMatchTransactionAttributeSource: Adding transactional method [get*] with attribute [PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT,readOnly] 
[<date>] DEBUG interceptor.NameMatchTransactionAttributeSource: Adding transactional method [update*] with attribute [PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT] 
[<date>] DEBUG interceptor.NameMatchTransactionAttributeSource: Adding transactional method [*] with attribute [PROPAGATION_MANDATORY,ISOLATION_DEFAULT] 

답변

4

주요 문제는 여기

텍사스했다 볼 수 있습니다 즉, WebApplicationContext를 DispatcherServlet에 넣으면 서비스가 아닌 컨트롤러의 @ Transactional beans 만 확인합니다. 절을 참조 15.2, 더 내용은 " DispatcherServlet을". 내가에게 서비스에 대한 구성 요소 검사와 같은 애플리케이션 컨텍스트 퍼팅

문제 :

0

당신은 당신의 트랜잭션 관리자로 JtaTransactionManager 선언을 해결했다. JBoss, WebSphere, WebLogic 등 본격적인 응용 프로그램 서버와 같은 JTA 가능 환경에서 프로그램이 실행되고 있습니까? 당신은 JTA 환경이없는 경우

, 당신은 대신 JPATransactionManager를 사용해야합니다 :

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
    <property name="entityManagerFactory" ref="entityManagerFactory"/> 
</bean> 
+0

예 - 나는 썬의 글래스 피시 애플리케이션 서버에서이 응용 프로그램을 실행 해요. 내 문제가 해결 된 것으로 생각합니다 :) 답장을 보내 주셔서 감사합니다! – Jan