Hello,
In my application, we have multiple layers through which a transaction must propagate through.
Service Layer (starts the transaction) --> Manager Layer --> DAO
All the methods in the service layer are configured to be transactional declaratively. However, the methods in the Manager & DAO are not configured to be transactional.
In this case, will the transaction starting from the service layer propagate to the called method in the Manager & DAO layer ?? Or else will I have to make the methods in the Manager & DAO layer transactional explicitly ??
Service layer code:
Manager Layer code:Code:public class LibraryServiceImpl implements LibraryService { private UserLibraryManager userLibraryManager; public void renameUserLibryNode(Integer nodeUid, String newName) throws LibException { userLibraryManager.renameUserLibryNode(nodeUid, newName); } public void setUserLibraryManager(UserLibraryManager userLibraryManager) { this.userLibraryManager = userLibraryManager; } }
DAO layer code:Code:public class UserLibraryManagerImpl implements UserLibraryManager { private UserLibraryDao userLibraryDao; public void renameUserLibryNode(Integer nodeUid, String newName) throws LibException { userLibraryDao.renameUserLibryNode(nodeUid, newName); } public void setUserLibraryDao(UserLibraryDao userLibraryDao) { this.userLibraryDao = userLibraryDao; } }
Code:public class UserLibraryDaoImpl implements UserLibraryDao { public void renameUserLibryNode(Integer nodeUid, String newName) throws LibException { // db update operation....might throw a checked exception. } }
Code:<!-- this is the service object that is made transactional --> <bean id="libraryService" class="x.y.service.LibraryService "/> <!-- the transactional advice (what 'happens'; see the <aop:advisor/> bean below) --> <tx:advice id="txAdvice" transaction-manager="txManager"> <!-- the transactional semantics... --> <tx:attributes> <!-- all methods starting with 'get' are read-only --> <tx:method name="get*" read-only="true"/> <!-- other methods use the default transaction settings (see below) --> <tx:method name="*"/> </tx:attributes> </tx:advice> <!-- ensure that the above transactional advice runs for any execution of an operation defined by the LibraryService interface --> <aop:config> <aop:pointcut id="libraryServiceOperation" expression="execution(* x.y.service.LibraryService.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="libraryServiceOperation"/> </aop:config>


Reply With Quote