Skip to content

HibernateJpaDialect exception translation misses concrete exceptions wrapped in Hibernate's ExecutionException #34633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bvklingeren opened this issue Mar 21, 2025 · 2 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@bvklingeren
Copy link

Currently, the spring-orm class org.springframework.orm.jpa.vendor.HibernateJpaDialect translates Hibernate exceptions to Spring exceptions, but these exceptions can be wrapped in instances of org.hibernate.sql.exec.ExecutionException as I have noticed. As a result, such an exception is translated into a generic org.springframework.orm.jpa.JpaSystemException, which is a pity, as I would like to add retry behavior around a deadlock occurrence, but only then.

In concrete, a org.hibernate.exception.LockAcquisitionException is thrown by Hibernate, which is then wrapped into an org.hibernate.sql.exec.ExecutionException (on line 325 in org.hibernate.sql.results.jdbc.internal.JdbcValuesResultSetImpl), which is then handled in an instance of org.springframework.orm.jpa.vendor.HibernateJpaDialect (method convertHibernateAccessException), and wrapped in a org.springframework.orm.jpa.JpaSystemException, since there is no translation for an ExecutionException.

I don't know if there are other cases where concrete translatable exceptions are 'lost' this way.

It would be nice if these wrapped exceptions could be unwrapped and translated, so we can act upon them correctly.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 21, 2025
@jhoeller jhoeller added in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 21, 2025
@jhoeller jhoeller self-assigned this Mar 21, 2025
@jhoeller jhoeller added this to the 6.2.6 milestone Mar 21, 2025
@bvklingeren
Copy link
Author

Thanks for the swift fix @jhoeller! Verified your changes and they work.

@jhoeller
Copy link
Contributor

Good to hear! Thanks for the immediate feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants