From a6c0136c30149f6ac3a19c75d13f105d6da1a57f Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Mon, 21 Jan 2019 18:24:59 +0100 Subject: [PATCH] [#720] Add workaround for EclipseLink issue that returns object of wrong type for count expression --- .../persistence/impl/PaginatedTypedQueryImpl.java | 8 ++++---- .../repository/AbstractEntityViewAwareRepository.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/impl/src/main/java/com/blazebit/persistence/impl/PaginatedTypedQueryImpl.java b/core/impl/src/main/java/com/blazebit/persistence/impl/PaginatedTypedQueryImpl.java index 314f49052d..2044f76f8b 100644 --- a/core/impl/src/main/java/com/blazebit/persistence/impl/PaginatedTypedQueryImpl.java +++ b/core/impl/src/main/java/com/blazebit/persistence/impl/PaginatedTypedQueryImpl.java @@ -137,7 +137,7 @@ private String getParameterName(Parameter parameter) { @Override public long getTotalCount() { - return (Long) countQuery.getSingleResult(); + return ((Number) countQuery.getSingleResult()).longValue(); } @Override @@ -155,10 +155,10 @@ public PagedList getResultList() { long totalSize = -1L; if (withCount) { if (entityId == null) { - totalSize = (Long) countQuery.getSingleResult(); + totalSize = ((Number) countQuery.getSingleResult()).longValue(); } else { Object[] result = (Object[]) countQuery.getSingleResult(); - totalSize = (Long) result[0]; + totalSize = ((Number) result[0]).longValue(); if (result[1] == null) { // If the reference entity id is not contained (i.e. has no position), we return this special value @@ -166,7 +166,7 @@ public PagedList getResultList() { firstRow = 0; } else { // The page position is numbered from 1 so we need to correct this here - int position = ((Long) result[1]).intValue() - 1; + int position = ((Number) result[1]).intValue() - 1; queryFirstResult = firstRow = position == 0 ? 0 : position - (position % pageSize); } } diff --git a/integration/spring-data/base/src/main/java/com/blazebit/persistence/spring/data/base/repository/AbstractEntityViewAwareRepository.java b/integration/spring-data/base/src/main/java/com/blazebit/persistence/spring/data/base/repository/AbstractEntityViewAwareRepository.java index e5291c30ab..08c590231f 100644 --- a/integration/spring-data/base/src/main/java/com/blazebit/persistence/spring/data/base/repository/AbstractEntityViewAwareRepository.java +++ b/integration/spring-data/base/src/main/java/com/blazebit/persistence/spring/data/base/repository/AbstractEntityViewAwareRepository.java @@ -328,7 +328,7 @@ public V findOne(ID id) { public long count() { TypedQuery countQuery = getCountQuery(null, getDomainClass()); - return countQuery.getSingleResult(); + return ((Number) countQuery.getSingleResult()).longValue(); } public boolean existsById(ID id) {