From my DAO method I need to return a result (even if exception occured). I try to do it in such a manner by it doesn't work in case of exception(I have an exception: don't flush the Session after an exception occurs
).
@Repository
@Transactional(rollbackFor=HibernateException.class)
public class UserDAO {
@Override
public boolean save(Proxy proxy) {
try{
sessionFactory.getCurrentSession().save(proxy);
}
catch(HibernateException e){
//TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return false;
}
return true;
}
}
However when I uncomment //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
all works like I expect. I know that documentation don't recommend to use this approach, but annotation rollback doesn't work for me. Can you explain, please, why? Can I modify the code to get it work, if it is possible?