Skip to content

Commit

Permalink
Don't use a limit in CommonPanacheQueryImpl#singleResultOptional and …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
yrodiere committed Jun 28, 2024
1 parent 742f226 commit 3c383b9
Showing 1 changed file with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -336,14 +335,9 @@ public <T extends Entity> T singleResult() {

@SuppressWarnings("unchecked")
public <T extends Entity> Optional<T> singleResultOptional() {
SelectionQuery hibernateQuery = createQuery(2);
SelectionQuery hibernateQuery = createQuery();
try (NonThrowingCloseable c = applyFilters()) {
List<T> list = hibernateQuery.getResultList();
if (list.size() > 1) {
throw new NonUniqueResultException();
}

return list.isEmpty() ? Optional.empty() : Optional.of(list.get(0));
return hibernateQuery.uniqueResultOptional();
}
}

Expand Down

0 comments on commit 3c383b9

Please sign in to comment.