-
Notifications
You must be signed in to change notification settings - Fork 38.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@Transactional with txManager name is cumbersome with base dao classes [SPR-9661] #14295
Comments
matthew inger commented ps: in the mean time, i've extended the AnnotationTransactionAttributeSource to override the getTransactionAttribute method. In this subclass, i'm first calling super.getTransactionAttribute(), then i'm looking for the
And to activate this, I'm using a bean factory post processor and replacing all of the definitions of AnnotationTransactionAttributeSource with my extension of it.
|
matthew inger commented PS: When i said this: Allow the transaction manager name, when left blank, to fallback to the annotation at the class level I mean let the actual targetClass be allowed to determine the transaction manager, instead of forcing it to the class where the method is implemented. |
Bulk closing outdated, unresolved issues. Please, reopen if still relevant. |
I have exact the same problem when trying to reuse methods from the base DAO class with transaction manager of the concrete DAO class. How to achieve that? The workaround by @mattinger from 2012 is unfortunately not working anymore due to multiple changes in the Spring code. Related: #14011 |
matthew inger opened SPR-9661 and commented
By embedding the transaction manager name in the
@Transactional
anotations, using base dao classes is cumbersome. Example:@Transactional
public class GenericDao<K extends Serializable,E> {
protected Class<E> mappedClass;
protected SessionFactory sessionFactory;
}
Now we have two subclasses, each of which will use different sessionfactory, and transaction manager (we don't need jta).
@Transactional
("fooTxManager")public class FooDao extends GenericDao<Long, Foo> {
...
}
@Transactional
("barTxManager")public class FooDao extends GenericDao<Long, Foo> {
...
}
The problem is that we'd have to override the getById() method otherwise that method will use the default transaction manager. Not a big deal with 1 method, but it is a big deal when there's a bunch of methods.
@Transactional
("barTxManager")public class FooDao extends GenericDao<Long, Foo> {
@Override
@Transactional
("barTxManager")public Foo getById(Long key) {
return super.getById(key);
}
...
}
I think a better approach would be to either:
a) Allow the transaction manager name, when left blank, to fallback to the annotation at the class level.
b) Separate the transaction semantics from the manager name with a new annotation:
@TransactionManager
("barTxManager")Affects: 3.1.1
The text was updated successfully, but these errors were encountered: