Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top