hibernateexceptionjpa

JPA/Hibernate exception handling


I'm using JPA/Hibernate (a newbie at them). When an exception occur (could be an unique constraint violation) I want to catch it and show some application meaning messages, instead of printing the stack trace.

Does Hibernate provide some tool to get info (maybe database independent) about exceptions?


Solution

  • HibernateException encapsulates the actual root cause than can provide you enough information for you to generate meaningful user-friendly messages. Read the Exception Handling section of their documentation.