hibernate/hibernate-orm · error · NonUniqueResultException
Query did not return a unique result: " + resultCount + " re
Error message
Query did not return a unique result: " + resultCount + " results were returned
What it means
Error "Query did not return a unique result: " + resultCount + " results were returned" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/ResultListTransformer.java:68
* {@link NonUniqueResultException} otherwise.
*
* @param <T> The result list element type
*
* @since 7.3
*/
static <T> ResultListTransformer<T> uniqueResultTransformer() {
return resultList ->
switch ( resultList.size() ) {
case 0, 1 -> resultList;
default -> {
final var first = resultList.get( 0 );
for ( int i = 1; i < resultList.size(); i++ ) {
final T current = resultList.get( i );
if ( !Objects.equals( first, current )
// also consider case of multiple select items in an Object[]
&& !( first instanceof Object[] array
&& !Arrays.equals( array, (Object[]) current ) ) ) {
throw new NonUniqueResultException( resultList.size() );
}
}
yield List.of( first );
}
};
}
}
View on GitHub (pinned to fad1729dce)
Solutions
- Add restricting criteria so the query returns at most one row.
- Use getResultList() if multiple results are valid.
When it happens
Trigger: A runtime precondition of the Hibernate API is violated.
Common situations: Occurs when application code or configuration does not satisfy the documented contract of the API being called.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/efdd472a33616e0e.
Report an issue: GitHub.