Issue
I have small problem. I can't catch exception in method. I need to catch ConstraintViolationException
to process it. Somebody know why it happens?
@Transactional(rollbackFor = Exception.class)
public void saveCustomer(Customer customer) {
Session session = sessionFactory.getCurrentSession();
try {
session.save(customer);
} catch (Throwable e) {
log.debug(e);
// Process exception
}
}
Solution
I ran into similar problem some days ago.
I looked at the StackTrace and used PersistenceException
.
Try it:
@Transactional(rollbackFor = Exception.class)
public void saveCustomer(Customer customer) {
Session session = sessionFactory.getCurrentSession();
try {
session.save(customer);
} catch (PersistenceException e) {
log.debug(e);
// Process exception
}
}
Answered By - Asgar
Answer Checked By - Robin (JavaFixing Admin)