views:

81

answers:

1

I finished a battery of DAO integration tests using JPA/Hibernate and many of them expect exceptions to be thrown. However, I have noticed that Hibernate seems to ignore the nice heirarchy of exceptions provided by the JPA spec and instead always throws the generic PersistenceException that wraps their Hibernate specific exception.

Am I doing something wrong somewhere or is this a bug in Hibernate?

+1  A: 

You could use @Repository and configure your repositories with Spring, then you can use Spring's DataAccessException hierarchy which is automatically translated quite nicely from both jpa and hibernate by Spring.

iwein
I am using JPA2 with EclipseLink, but an unique constraint violation is just wrapped to a `org.springframework.orm.jpa.JpaSystemException`, which is: "JPA-specific subclass of UncategorizedDataAccessException, for JPA system errors that do not match any concrete `org.springframework.dao` exceptions". Should not it translates to a nicer interface instead?
pihentagy