GenericJDBCException handling


#1

Hello,

in Hibernate 5.3, if a GenericJDBCException occurs, for example when flushing same changes into the database the exception is wrapped inside a PersistenceException[1].

I’m working to upgrade Hibernate from version 3.6. In such version GenericJDBCException were being directly thrown. So I’ve been forced to do some changes in my code in some try-catch blocks because they were no longer catching the exception properly (now I need to catch PersistenceException instead of GenericJDBCException)

I can do this changes in my code and also in some of the test cases affected by this change, but I’m still a bit concerned of third party code that can extend my application which I can’t control. After upgrading hibernate, if that code is managing the exceptions by catching GenericJDBCException it will stop working as expected…

What is your recommendation in this case? Do you have any suggestion about how I can manage this?

Thank you in advance.

[1] https://github.com/hibernate/hibernate-orm/blame/master/hibernate-core/src/main/java/org/hibernate/internal/ExceptionConverterImpl.java#L149


#2

Just write the Hibernate exception into your own DataAceessException and your clients will be isolated from the underlying exception thrown by Hibernate.