NonUniqueResultException Java Origin: Application & API Last updated 12 Oct 2026

IncorrectResultSizeDataAccessException: query did not return a unique result: 2

A query expected one row but found several.

Exact message you may see query did not return a unique result
Seen on: Java

Meaning

Spring Data repository methods returning a single entity/Optional throw when multiple rows match. The data or the query assumption is wrong.

Common causes

  • Duplicate data where uniqueness was assumed
  • findBy... returning single instead of List
  • Missing unique constraint

⚡ Quick fix

  1. Return a List and handle duplicates
  2. Add a unique constraint
  3. Use findFirstBy… with ordering when you want one

Detailed fix by platform

Java

  1. Optional<User> findFirstByEmailOrderByIdDesc(String email);

How to diagnose

  1. Query — Which method?
  2. Data — Why several rows?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

08P01 — ERROR: bind message supplies 2 parameters, but prepared statement requires 1 (PostgreSQL)08P011093 — MySQL ERROR 1093 (HY000): You can't specify target table 'x' for update in FROM clause (MySQL)10931175 — MySQL ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column (MySQL)11751241 — MySQL ERROR 1241 (21000): Operand should contain 1 column(s) (MySQL)124142P18 — ERROR: could not determine data type of parameter $1 (PostgreSQL)42P18currval not defined — ERROR: currval of sequence "x" is not yet defined in this session (PostgreSQL)currval not definedHibernate ConstraintViolationException — org.hibernate.exception.ConstraintViolationException: could not execute statement (Java)Hibernate ConstraintV…LazyInitializationException — org.hibernate.LazyInitializationException: could not initialize proxy - no Session (Java)LazyInitializationExc…NonUnique…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.