diff --git a/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/AbstractJpaOperations.java b/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/AbstractJpaOperations.java index ebcb984482cf59..866add3b39df47 100644 --- a/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/AbstractJpaOperations.java +++ b/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/AbstractJpaOperations.java @@ -16,6 +16,7 @@ import jakarta.transaction.TransactionManager; import org.hibernate.Session; +import org.hibernate.jpa.HibernateHints; import io.agroal.api.AgroalDataSource; import io.quarkus.agroal.DataSource; @@ -320,6 +321,7 @@ public Stream streamAll(Class entityClass, Sort sort) { public long count(Class entityClass) { return (long) getEntityManager(entityClass) .createQuery("SELECT COUNT(*) FROM " + PanacheJpaUtil.getEntityName(entityClass)) + .setHint(HibernateHints.HINT_READ_ONLY, true) .getSingleResult(); } @@ -333,7 +335,9 @@ public long count(Class entityClass, String panacheQuery, Object... params) { return (long) bindParameters( getEntityManager(entityClass) .createQuery(PanacheJpaUtil.createCountQuery(entityClass, panacheQuery, paramCount(params))), - params).getSingleResult(); + params) + .setHint(HibernateHints.HINT_READ_ONLY, true) + .getSingleResult(); } catch (IllegalArgumentException x) { throw NamedQueryUtil.checkForNamedQueryMistake(x, panacheQuery); } @@ -349,7 +353,9 @@ public long count(Class entityClass, String panacheQuery, Map return (long) bindParameters( getEntityManager(entityClass) .createQuery(PanacheJpaUtil.createCountQuery(entityClass, panacheQuery, paramCount(params))), - params).getSingleResult(); + params) + .setHint(HibernateHints.HINT_READ_ONLY, true) + .getSingleResult(); } catch (IllegalArgumentException x) { throw NamedQueryUtil.checkForNamedQueryMistake(x, panacheQuery); }