开发者

Spring+OpenJPA TransactionRequiredException from delegate service method

开发者 https://www.devze.com 2023-03-08 13:13 出处:网络
We\'re running into problems with Spring 3.0.5 transactional management and OpenJPA 2.0.1 and we can\'t seem to pinpoint the problem so any help is appreciated.

We're running into problems with Spring 3.0.5 transactional management and OpenJPA 2.0.1 and we can't seem to pinpoint the problem so any help is appreciated.

The architecture is can be broken down as follows:

service-layer

@Autowired
private DAOInterface daoReference;
....
public void doStuff() {
     boolean test = performCheck();
}
....
private boolean performCheck() {
     return daoReference._performDAOCheck();
}

DAO-layer

@PersistenceContext
private EntityManager entityManager;
.....
@Transactional
public boolean _performDAOCheck() {
     boolean result = true;
     // fetch entity manager, perform something and return boolean value
     return result;
}

This code performs as it should but we really dislike the existence of transactional demarcation on DAO-layer and would like to transfer that to service-layer above.

However should we move the @Transactional annotation to service-layer delegate method and remove it from DAO layer, we get the javax.persistence.TransactionRequiredException which indicates that a transaction is required but is not active.

The question is - why and how do we "activate" the transaction from delegate method? Mind you, we've tried various transaction propagation modifiers, but it didn't seem to 开发者_JAVA百科do anything useful (REQUIRES_NEW is the only actually applicable in this context, but we tried the others just to be on the safe side).

The application stack is as follows:

  1. Spring 3.0.5
  2. Bitronix 2.1.1
  3. OpenJPA 2.0.1
  4. Tomcat 6.0.32
  5. JUnit 4.8.2 is used as testing framework


For future reference - it seems we've nailed down the problem - it's about Spring AOP proxy which doesn't notice local method calls.

If service-layer performCheck() is moved to another spring bean, injected and then called, proxy correctly generates a new transactional context and the thing works like a charm.

0

精彩评论

暂无评论...
验证码 换一张
取 消