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开发者_JAVA技巧 this problem before?
Thanks in advance
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.
精彩评论