From c66b27d1939e58a5e6509bc15277c7380fd62e3a Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Mon, 30 Sep 2024 09:15:07 +0800 Subject: [PATCH] HHH-18674 Expose result count of NonUniqueResultException --- .../java/org/hibernate/NonUniqueResultException.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hibernate-core/src/main/java/org/hibernate/NonUniqueResultException.java b/hibernate-core/src/main/java/org/hibernate/NonUniqueResultException.java index 2fb32dae4d..443180679b 100644 --- a/hibernate-core/src/main/java/org/hibernate/NonUniqueResultException.java +++ b/hibernate-core/src/main/java/org/hibernate/NonUniqueResultException.java @@ -15,6 +15,9 @@ import org.hibernate.query.Query; * @author Gavin King */ public class NonUniqueResultException extends HibernateException { + + private final int resultCount; + /** * Constructs a {@code NonUniqueResultException}. * @@ -22,6 +25,15 @@ public class NonUniqueResultException extends HibernateException { */ public NonUniqueResultException(int resultCount) { super( "Query did not return a unique result: " + resultCount + " results were returned" ); + this.resultCount = resultCount; + } + + /** + * Get the number of actual results. + * @return number of actual results + */ + public int getResultCount() { + return this.resultCount; } }