Tuesday, 17 September 2013

@Transactional in @Service ignored

@Transactional in @Service ignored

If I put 'mode="aspectj"' into 'tx:annotation-driven' tag, then
Spring-data handles transactions only in @Repository files, and not in
@Service classes.
Here is my @Service to retrieve users:
@Service
public class RepositoryAuthService implements AuthService{
@Resource
AuthUserRepository userRepository;
@Transactional(propagation = Propagation.REQUIRED)
@Override
public User findByCredentials(String userName, String password){
User user = userRepository.getByCredentials(userName, password);
TransactionAspectSupport.currentTransactionStatus().toString();
...
}
Here is my spring-context:
<tx:annotation-driven mode="aspectj"
transaction-manager="transactionManager" />
<jpa:repositories base-package="my.jpatest.dao.auth" />
<context:component-scan base-package="my.jpatest.dao.auth">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Repository" />
</context:component-scan>
<bean class="my.jpatest.dao.auth.RepositoryAuthService" id="authService" />
Exception:
org.springframework.transaction.NoTransactionException: No transaction
aspect-managed TransactionStatus in scope
at
org.springframework.transaction.interceptor.TransactionAspectSupport.currentTransactionStatus(TransactionAspectSupport.java:111)
at
my.jpatest.dao.auth.RepositoryAuthService.findByCredentials(RepositoryAuthService.java:34)
I tried 'aspectj' with 'proxy-target-class="true"' but did not help.
Without mode="aspectj" everything is fine: the connection remains after
the repository-call as expected.
There is a detailed article about that, but this is quite long:
http://doanduyhai.wordpress.com/2011/11/20/spring-transactional-explained/
Any tips?
Regards: bence

No comments:

Post a Comment