Hello.
I have multiple service objects, while methods in service objects represent use cases.
If I call the method from the other method in the same service object, then the second (called) method uses the same transaction as the first (caller), because of default propagation REQUIRED is applied.
.. as is shown in the following pseudo code:
@Transactional
public class PersonService {
private PersonDAO personDAO;
public void otherMethod() {
...
}
public void savePerson(Person person) {
otherMethod();
personDAO.save(person);
...
}
}
But I need to call service methods of different service objects, because some use cases use other use cases. I also need all those called methods to be done as a single transaction.
@Transactional
public class OrderService {
private OrderDAO orderDAO;
public void saveOrder(Person person, Order order) {
PersonService personService = CONTEXT.getBean("personService");
personService.savePerson(person);
orderDAO.save(order);
}
}
If I do it like that, the new transaction proxy is created and all personService stuff is executed in the new transaction. How to configure @Transactional annotated objects or Spring beans to do all service stuff in single transaction?
I have Hibernate sessionfactory, DAOs and services beans simply configured in Spring configuration XML, using autowiring and transaction annotation config. I prefer using @transactional annotated service classes, but if I had to use more complex Spring transaction configuration to achieve the goal I won't have any problem with it.
Thank you in advance.