Skip to content

HibernateExceptionTranslator translating to InvalidDataAccessApiUsageException when using vanilla Hibernate [SPR-14681] #19245

Closed
@spring-projects-issues

Description

@spring-projects-issues

Koen Serneels opened SPR-14681 and commented

The new org.springframework.orm.hibernate5.HibernateExceptionTranslator uses a fallthrough in the sense that it first tries to map the exception using vanilla Hibernate (SessionFactoryUtils). If no translation could be done it tries JPA via EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible().

The latter troubles us as it is translating IllegalStateException to InvalidDataAccessApiUsageException. I'm not really sure why IllegalStateException and IllegalArgumentException get this special treatment, but ok. So now we suddenly end up with translated exceptions that weren't translated before. Since these extra translations are in context of JPA (as it is called 'convertJpaAccessExceptionIfPossible') this also makes no sense as we are not using JPA but vanilla Hibernate.

So, what is the correct way to make sure that we only get Hibernate exceptions translated? Afaic the HibernateExceptionTranslator has no options to turn off JPA translation and the LocalSessionFactoryBean extends HibernateExceptionTranslator without the option to inject another implementation. Wouldn't it make more sense to have the HibernateExceptionTranslator JPA unaware and add another translator in case JPA is actually used?


Affects: 4.3.2

Reference URL: https://stackoverflow.com/questions/39393116/how-to-deactivate-spring-data-exception-translation

Issue Links:

Referenced from: commits 4b44553, 34ab818

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions