We have base generic manager which is inherited by all managers. Base manager is annotated with @Transactional annotations.
There are 2 groups of transactional services:
x.y.service1.*
- have to be managed bytransactionManager1
x.y.service2.*
- have to be managed bytransactionManager2
How can transactions be configured without nessesity to override ALL transactional methods and specify transaction manager?
@Transactional(readOnly = true)
public abstract class GenericManagerImpl<D extends IGenericDao, T extends BaseObject, PK extends Serializable>
implements IGenericManager<T, PK> {
protected D dao;
@Autowired
public void setDao(D dao) {
this.dao = dao;
}
@Transactional(readOnly = false)
public void save(T object) {
dao.save(object);
}
@Transactional(readOnly = false)
public void remove(T object) {
dao.remove(object);
}
}
@Service
class UserManagerImpl
extends GenericManagerImpl<IUserDao, User, Long>
implements IUserManager {
// Everything is OK. User is managed by txManager1
}
@Service
class BillingManagerImpl
extends GenericManagerImpl<IBillingDao, Billing, Long>
implements IBillingManager {
@Override
@Transactional(readOnly = false, value="txManager2") // <--have to override method only to specify txManager
public void save(final Billing billing ) {
super.save(billing);
}
@Override
@Transactional(readOnly = false, value="txManager2") // <--have to override method only to specify txManager
public void remove(final Billing billing ) {
super.remove(billing);
}
}