Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Single transaction through multiple service objects [Spring]

807588Jun 16 2009 — edited Jun 17 2009
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 15 2009
Added on Jun 16 2009
3 comments
2,233 views