Question

Project setup: Spring 3.0.5 / JPA 2 / Hibernate / @Transactional

We work with several different Data Sources (and hence different transaction managers), but have common Service base classes, as a lot of the functionality is reused.

So we thought we'd solve this by using Custom Annotations. We define all methods in an abstract base class, and create one empty implementation class per Transaction Manager.

Now the problem is:

In AbstractFallbackTransactionAttributeSource, this is the lookup that is being done:

TransactionAttribute txAtt = findTransactionAttribute(specificMethod);
// ...
// Second try is the transaction attribute on the target class.
txAtt = findTransactionAttribute(specificMethod.getDeclaringClass());

First the method is checked, then the class that declares the method (and its ancestors). But in our context, the custom annotation resides in a subclass that can't be found by going upwards.

So how can we solve this problem?

[I also asked this question in the Spring Community Forum]

Was it helpful?

Solution 2

For the time being, we solved this issue by providing

  1. our own subclass of AnnotationTransactionAttributeSource which does a lookup on the target class first and then delegates to the super class
  2. A BeanFactoryPostProcessor that substitues our implementation for the original AnnotationTransactionAttributeSource bean definition that is created internally by <tx:annotation-driven>

.

OTHER TIPS

Great catch. I don't know a good solution but as a workaround, you can override the methods in question in the implementation like so:

@Override
void method(...)
    // Just to work around a bug in AbstractFallbackTransactionAttributeSource
    super.method(...);
}

that will make the @Transactional visible but it's ugly :-/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top