How do I catch the constraint violation exception from EclipseLink?

后端 未结 6 2376
-上瘾入骨i
-上瘾入骨i 2021-02-19 06:54

I am using EclipseLink in my web application, and I am having a hard time gracefully catching and handling Exceptions it generates. I see from this thread what seems to be a si

6条回答
  •  难免孤独
    2021-02-19 07:05

    Edit your persistence.xml adding the following property:

    property name="eclipselink.exception-handler" value="your.own.package.path.YourOwnExceptionHandler"

    Now create the class YourOwnExceptionHandler (on the correct package). It requires to implement org.eclipse.persistence.exceptions.ExceptionHandler.

    Create a non argument constructor and the required method handleException(...).

    Inside this method, you can catch the exceptions!

提交回复
热议问题