关于hibernateTemplate的异常处理?
菜鸟求教!
请问,在项目中有DAO层和service层。通过spring在service层中配置事务管理。在DAO层中使用hibernateTemplate对数据库做相关操作,service层中调用DAO层的方法,如果我在service的方法中写try catch,spring还会对事务进行管理吗?
[解决办法]
try catch后你有没有抛出,如果没有,肯定事务不会回滚的。
[解决办法]
还是直接上代码吧
public void saveTicr(TInfCardRecord ticr) throws ServiceException { // TODO Auto-generated method stub String str = ticr.getTicrId(); boolean b = str == null || "".equals(str); try { if(b){ ticr.setTicrId(Tools.getRandom()); ticr.setTicrDate(new Date()); } this.infCardRecordDao.saveTicr(ticr); } catch (Exception e) { // TODO: handle exception if(b){ throw new ServiceException("save ticr fail"); }else{ throw new ServiceException("update ticr fail"); } } }