We're building a new application in Spring MVC with Hibernate as persistence solution. There 're 2 solutions to approach the data layer:
1) In some cases the controller invokes the DAO layer directly. This is done because no business checks need to be performed. So we're bypassing the Service layer for such cases.
Implementing a Service layer for this would turn up in just delegating methods to the DAO layer.
So we're doing the following: Controller -> DAO
2) In other cases we do need some business checks. For this, we use the conventional way:
Controller -> Service -> DAO
In Spring we need to demarcate a Transaction, therefore we put @Transaction annotation on all DAO methods. This works fine doing the Controller -> DAO way. But if we're doing the Controller -> Service -> DAO way, we also need to put a @Transaction annotation on the service method.
This means that we're having nested transactions in some cases. Is this a good approach? Do we need to create a new transaction (REQUIRES_NEW) on all DAO methods or rather use the existing transaction (REQUIRED) if one exists?
Can someone enlighten me on this?