Skip to content

SessionFactoryUtils.convertHibernateAccessException() improperly swallows underlying HibernateException [SPR-7933] #12588

Closed

Description

@spring-projects-issues

Eric Sirianni opened SPR-7933 and commented

The convertHibernateAccessException() method in SessionFactoryUtils does not properly chain the source HibernateException into the transformed Spring IncorrectResultSizeDataAccessException.

if (ex instanceof NonUniqueResultException) {
    return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1);
}

The root HibernateException is swallowed, and along with it the stack trace with the actual line of code that generated the Hibernate error. This makes it nearly impossible to debug these failures.

The rest of the 'if' branches in convertHibernateAccessException() do appear to be properly chaining the underlying HibernateException into the newly constructed Exception:

if (ex instanceof PropertyValueException) {
    return new DataIntegrityViolationException(ex.getMessage(), ex);
}
if (ex instanceof PersistentObjectException) {
    return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
}

Affects: 3.0.5

Issue Links:

Referenced from: commits b0b1116

5 votes, 0 watchers

Activity

  1. spring-projects-issues commented on Mar 22, 2011

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    Thanks, Eric. A new InvalidResultSizeDataAccessException constructor has been added that accepts and propagates the wrapped exception appropriately. Both SessionFactoryUtils as well as EntityManagerUtils have been updated to make use of it.

    Note that this issue won't be available in nightly snapshots until #12721 is resolved.

  2. added this to the 3.1 M2 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions