Description
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:
- TypeConverterSupport does not propagate custom exceptions anymore [SPR-14661] #19225 TypeConverterSupport does not propagate custom exceptions anymore
- Hibernate5 LocalSessionFactoryBean does not translate javax.persistence exceptions [SPR-14455] #19024 Hibernate5 LocalSessionFactoryBean does not translate javax.persistence exceptions