我有一个名为的服务方法add()
,它用@Transactional
.
我调用它,但是当在相应的 DAO 方法中发生 ConstraintViolationException 时,即使我指定不回滚,它也会回滚事务。
我希望它ConstraintViolationException
会被捕获,而不是它NotFoundException
会抛出检查异常。
@Override
@Transactional(noRollbackFor = ConstraintViolationException.class)
public User add(User user) throws NotFoundException {
try {
result = userDao.add(user);
} catch (RuntimeException e) {
throw new NotFoundException("Couldn't find group");
}
}
有没有办法在ConstraintViolationException
没有事务回滚的情况下捕获?
我正在使用弹簧 3.1.1 和休眠 3.6。