How to handle JPA unique constraint violations?

后端 未结 8 1786
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 14:05

When a unique constraint is violated, a javax.persistence.RollbackException is thrown. But there could be multiple reasons to throw a RollbackException

8条回答
  •  南方客
    南方客 (楼主)
    2020-12-05 14:19

    You can do like this :

    StringWriter writer=new StringWriter(); //remains the message from stack trace.
    e.printStackTrace(new PrintWriter(writer));
    String message=writer.toString(); // gets the message of full stack trace.
    

    And then view the information of exception.

提交回复
热议问题