We're updating the issue view to help you get more done. 

query.getSingleResult() throws org.hibernate.NonUniqueResultException instead of javax.persistence.NonUniqueResultException

Description

The JPA spec (or at least its javadoc) mandates that javax.persistence.TypedQuery#getSingleResult throws a javax.persistence.NonUniqueResultException when the query has more than one result.

Since 5.2, we are supposed to follow the JPA spec by default, regardless of the booting method (JPA or native), unless hibernate.native_exception_handling_51_compliance is set to true.

However, we currently behave like this:

  • If we booted using JPA, getSingleResult() throws a javax.persistence.NonUniqueResultException

  • If we booted using native APIs, getSingleResult() throws a org.hibernate.NonUniqueResultException

The second item seems wrong. Especially since it's not affected by setting hibernate.native_exception_handling_51_compliance to false or hibernate.jpa.compliance.query to true.

I only witnessed this behavior in 5.4, but I believe it also affects 5.3 and 5.2.

Environment

None

Status

Assignee

Yoann Rodière

Reporter

Yoann Rodière

Fix versions

Labels

None

backPortable

Backport?

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Components

Affects versions

5.2.18
5.4.1
5.3.9

Priority

Major