Configuring web.xml in a Spring MVC with Hibernate project.DispatcherServlet and ContextLoaderListener have each a sessionFactory

大兔子大兔子 提交于 2019-12-06 16:33:53

If your "unit of work" cannot be automatically per request, I think you can create it manually in your service layer using a transaction. Something like this:

public Object serviceMethod(params) {
   TransactionTemplate transactionTemplate; 
   transactionTemplate.execute(new TransactionCallbackWithoutResult() {
         public void doInTransactionWithoutResult(TransactionStatus status) {
         try {
        // call your DAO's to update/delete/... and set values to service
         } catch (DAOException e) {
        LOGGER.error(e);
        throw new ServiceException(e);
         }
    }
});
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!