diff --git a/src/main/java/org/springframework/data/jpa/provider/HibernateUtils.java b/src/main/java/org/springframework/data/jpa/provider/HibernateUtils.java index ec3aa1665..d6d16329e 100644 --- a/src/main/java/org/springframework/data/jpa/provider/HibernateUtils.java +++ b/src/main/java/org/springframework/data/jpa/provider/HibernateUtils.java @@ -33,7 +33,7 @@ import org.springframework.util.ReflectionUtils; * @since 1.10.2 * @soundtrack Benny Greb - Soulfood (Live, https://www.youtube.com/watch?v=9_ErMa_CtSw) */ -@SuppressWarnings({ "deprecation", "rawtypes" }) +@SuppressWarnings("rawtypes") public abstract class HibernateUtils { private static final List TYPES = Arrays.asList("org.hibernate.jpa.HibernateQuery", @@ -83,7 +83,7 @@ public abstract class HibernateUtils { /** * Return the query string of the underlying native Hibernate query. - * + * * @param query * @return */ @@ -91,7 +91,7 @@ public abstract class HibernateUtils { if (HIBERNATE_QUERY_INTERFACE != null && QUERY_STRING_METHOD != null && HIBERNATE_QUERY_INTERFACE.isInstance(query)) { - return String.class.cast(ReflectionUtils.invokeMethod(QUERY_STRING_METHOD, query)); + return (String) ReflectionUtils.invokeMethod(QUERY_STRING_METHOD, query); } if (HIBERNATE_QUERY_INTERFACE != null && !HIBERNATE_QUERY_INTERFACE.isInstance(query)) { @@ -111,6 +111,28 @@ public abstract class HibernateUtils { return HIBERNATE_VERSION.isGreaterThanOrEqualTo(version); } + /** + * Returns whether the current version of Hibernate supports {@link javax.persistence.Tuple} as a return type for + * native queries. + * + * @since 1.11.23 + */ + public static boolean supportsTuples() { + + return isVersionInInterval(HIBERNATE4_VERSION_SUPPORTING_TUPLES, HIBERNATE5_VERSION) + || isVersionOrBetter(HIBERNATE5_VERSION_SUPPORTING_TUPLES); + } + + /** + * Returns whether the current version of Hibernate supports {@link javax.persistence.Tuple} as a return type for + * native queries. + * + * @since 1.11.23 + */ + public static boolean supportsTuplesForNativeQueries() { + return isVersionOrBetter(HIBERNATE5_VERSION_SUPPORTING_TUPLES); + } + /** * Returns whether the currently used version of Hibernate is in the given interval of versions. * @@ -119,27 +141,9 @@ public abstract class HibernateUtils { * @param upperExcluding upper version bound to compare to. The upper version bound is exclusive. Must not be * {@literal null}. * @return whence lowerIncluding <= Hibernate version < upperExcluding. + * @since 1.11.23 */ private static boolean isVersionInInterval(Version lowerIncluding, Version upperExcluding) { return HIBERNATE_VERSION.isGreaterThanOrEqualTo(lowerIncluding) && HIBERNATE_VERSION.isLessThan(upperExcluding); } - - /** - * Returns wether the current version of Hibernate supports {@link javax.persistence.Tuple} as a return type for - * native queries. - */ - public static boolean supportsTuples() { - - return HibernateUtils.isVersionInInterval(HIBERNATE4_VERSION_SUPPORTING_TUPLES, HIBERNATE5_VERSION) - || HibernateUtils.isVersionOrBetter(HIBERNATE5_VERSION_SUPPORTING_TUPLES); - } - - /** - * Returns wether the current version of Hibernate supports {@link javax.persistence.Tuple} as a return type for - * native queries. - */ - public static boolean supportsTuplesForNativeQueries() { - - return HibernateUtils.isVersionOrBetter(HIBERNATE5_VERSION_SUPPORTING_TUPLES); - } } diff --git a/src/main/java/org/springframework/data/jpa/repository/query/AbstractJpaQuery.java b/src/main/java/org/springframework/data/jpa/repository/query/AbstractJpaQuery.java index 348958a48..fb9c8ce4d 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/AbstractJpaQuery.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/AbstractJpaQuery.java @@ -51,7 +51,7 @@ import org.springframework.util.Assert; /** * Abstract base class to implement {@link RepositoryQuery}s. - * + * * @author Oliver Gierke * @author Thomas Darimont * @author Mark Paluch @@ -67,7 +67,7 @@ public abstract class AbstractJpaQuery implements RepositoryQuery { /** * Creates a new {@link AbstractJpaQuery} from the given {@link JpaQueryMethod}. - * + * * @param method * @param em */ @@ -92,7 +92,7 @@ public abstract class AbstractJpaQuery implements RepositoryQuery { /** * Returns the {@link EntityManager}. - * + * * @return will never be {@literal null}. */ protected EntityManager getEntityManager() { @@ -101,7 +101,7 @@ public abstract class AbstractJpaQuery implements RepositoryQuery { /** * Returns the {@link JpaMetamodel}. - * + * * @return */ protected JpaMetamodel getMetamodel() { @@ -152,7 +152,7 @@ public abstract class AbstractJpaQuery implements RepositoryQuery { /** * Applies the declared query hints to the given query. - * + * * @param query * @return */ @@ -167,7 +167,7 @@ public abstract class AbstractJpaQuery implements RepositoryQuery { /** * Protected to be able to customize in sub-classes. - * + * * @param query must not be {@literal null}. * @param hint must not be {@literal null}. */ @@ -181,7 +181,7 @@ public abstract class AbstractJpaQuery implements RepositoryQuery { /** * Applies the {@link LockModeType} provided by the {@link JpaQueryMethod} to the given {@link Query}. - * + * * @param query must not be {@literal null}. * @param method must not be {@literal null}. * @return @@ -203,7 +203,7 @@ public abstract class AbstractJpaQuery implements RepositoryQuery { /** * Configures the {@link javax.persistence.EntityGraph} to use for the given {@link JpaQueryMethod} if the * {@link EntityGraph} annotation is present. - * + * * @param query must not be {@literal null}. * @param method must not be {@literal null}. * @return @@ -230,7 +230,7 @@ public abstract class AbstractJpaQuery implements RepositoryQuery { /** * Returns the type to be used when creating the JPA query. - * + * * @return * @since 2.0.5 */ @@ -249,7 +249,7 @@ public abstract class AbstractJpaQuery implements RepositoryQuery { /** * Creates a {@link Query} instance for the given values. - * + * * @param values must not be {@literal null}. * @return */ @@ -257,7 +257,7 @@ public abstract class AbstractJpaQuery implements RepositoryQuery { /** * Creates a {@link TypedQuery} for counting using the given values. - * + * * @param values must not be {@literal null}. * @return */ @@ -269,7 +269,7 @@ public abstract class AbstractJpaQuery implements RepositoryQuery { /** * Creates a new {@link TupleConverter} for the given {@link ReturnedType}. - * + * * @param type must not be {@literal null}. */ public TupleConverter(ReturnedType type) { @@ -279,7 +279,7 @@ public abstract class AbstractJpaQuery implements RepositoryQuery { this.type = type; } - /* + /* * (non-Javadoc) * @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object) */ diff --git a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java index 722c59cee..c88ecad21 100644 --- a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java @@ -2261,11 +2261,10 @@ public class UserRepositoryTests { List> listOfMaps = repository.findListOfMaps(); - assertThat(listOfMaps, Matchers.> hasSize(4)); + assertThat(listOfMaps, hasSize(4)); for (Map map : listOfMaps) { - assertThat(map.entrySet(), Matchers.hasSize(2)); + assertThat(map.entrySet(), hasSize(2)); } - } @Test(expected = DataIntegrityViolationException.class) // DATAJPA-1535