From 3c383b9229b31bc2523166e3a1e938bff500956e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Fri, 28 Jun 2024 12:05:05 +0200 Subject: [PATCH] Don't use a limit in CommonPanacheQueryImpl#singleResultOptional and simplify code Don't use a limit to avoid warnings such as: > HHH000104: firstResult/maxResults specified with collection fetch; applying in memory! Simplify code because... we can. --- .../panache/common/runtime/CommonPanacheQueryImpl.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java b/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java index 58c5cb2d7e705..42a14c283900a 100644 --- a/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java +++ b/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java @@ -14,7 +14,6 @@ import java.util.stream.Stream; import jakarta.persistence.LockModeType; -import jakarta.persistence.NonUniqueResultException; import org.hibernate.Filter; import org.hibernate.Session; @@ -336,14 +335,9 @@ public T singleResult() { @SuppressWarnings("unchecked") public Optional singleResultOptional() { - SelectionQuery hibernateQuery = createQuery(2); + SelectionQuery hibernateQuery = createQuery(); try (NonThrowingCloseable c = applyFilters()) { - List list = hibernateQuery.getResultList(); - if (list.size() > 1) { - throw new NonUniqueResultException(); - } - - return list.isEmpty() ? Optional.empty() : Optional.of(list.get(0)); + return hibernateQuery.uniqueResultOptional(); } }