how why hibernate changed HibernateException to (unchecked) RuntimeException

 

Questions


I know that in some version Hibernate exceptions were changed to be unchecked. what is the reason? is this a philosophy issue or practical one?

 

 

————————————————-

Answer

Practical. So you don’t have to wrap every one of your operations regarding Hibernate in try catch blocks.

Taken from Java Persistence with Hibernate:

A history of exceptions — Exceptions
and how they should be handled always
end in heated debates between Java
developers. It isn’t surprising that
Hibernate has some noteworthy history
as well. Until Hibernate 3.x, all
exceptions thrown by Hibernate were
checked exceptions, so every Hibernate
API forced the developer to catch and
handle exceptions. This strategy was
influenced by JDBC , which also throws
only checked exceptions. However, it
soon became clear that this doesn’t
make sense, because all exceptions
thrown by Hibernate are fatal. In many
cases, the best a developer can do in
this situation is to clean up, display
an error message, and exit the
application. Therefore, starting with
Hibernate 3.x, all exceptions thrown
by Hibernate are subtypes of the
unchecked Runtime Exception, which is
usually handled in a single location
in an application. This also makes any
Hibernate template or wrapper API
obsolete.

exception,hibernate,java

Facebook Comments

Post a comment