Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to catch DataIntegrityViolationException with wrapped transaction

I'm using Spring 3 for managing DB transactions. Whenever an exception is raised, I catch the exception and return the corresponding message. But when Spring commits the transaction, the exception is raised again and wrapped in a org.springframework.dao.DataIntegrityValidationException. How can I handle that exception? should I use interceptors or something else? Has anyone already had this problem before?

Thanks in advance

like image 801
Neuquino Avatar asked Nov 26 '10 20:11

Neuquino


1 Answers

If your transaction boundaries are at your service layer (if you have one, which you should), then you should catch the exception outside of the boundary. The way Spring works is if an exception bubbles outside the transaction boundary, the transaction is rolled back. By catching the exception you are stopping that process, which you probably dont want.

Interceptors are a good way to deal with the exception outside of the transaction boundary.

like image 115
hvgotcodes Avatar answered Sep 30 '22 17:09

hvgotcodes