From 6f2273d74981f2413a08285b85ee2502bea9ddb7 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Fri, 21 Jan 2022 23:48:58 -0600 Subject: [PATCH] HHH-15030 - SelectQuery, MutationQuery, etc SelectQuery as typed --- .../engine/spi/SessionDelegatorBaseImpl.java | 7 +- .../AbstractSharedSessionContract.java | 29 +++- .../main/java/org/hibernate/query/Query.java | 2 +- .../org/hibernate/query/QueryProducer.java | 14 +- .../org/hibernate/query/SelectionQuery.java | 126 +++++++-------- .../hibernate/query/spi/AbstractQuery.java | 5 +- .../query/spi/AbstractSelectionQuery.java | 135 ++++++++-------- .../query/sql/internal/NativeQueryImpl.java | 2 - .../query/sqm/SqmSelectionQuery.java | 92 +++++------ .../query/sqm/internal/QuerySqmImpl.java | 63 ++++---- ...ryImpl.java => SqmSelectionQueryImpl.java} | 150 ++++++++++-------- .../sqm/untyped/BasicUntypedQueryTests.java | 49 ++++-- 12 files changed, 372 insertions(+), 302 deletions(-) rename hibernate-core/src/main/java/org/hibernate/query/sqm/internal/{SqmSelectQueryImpl.java => SqmSelectionQueryImpl.java} (73%) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java index f1fdd141b1..4783826880 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java @@ -495,10 +495,15 @@ public class SessionDelegatorBaseImpl implements SessionImplementor { } @Override - public SelectionQuery createSelectQuery(String hqlString) { + public SelectionQuery createSelectQuery(String hqlString) { return queryDelegate().createSelectQuery( hqlString ); } + @Override + public SelectionQuery createSelectQuery(String hqlString, Class resultType) { + return queryDelegate().createSelectQuery( hqlString, resultType ); + } + @Override public QueryImplementor createQuery(String queryString, Class resultType) { return queryDelegate().createQuery( queryString, resultType ); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java index 3bfec239e4..9b4416d653 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java @@ -11,6 +11,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.sql.SQLException; import java.util.List; +import java.util.Locale; import java.util.TimeZone; import java.util.UUID; import java.util.function.Function; @@ -56,6 +57,7 @@ import org.hibernate.query.IllegalNamedQueryOptionsException; import org.hibernate.query.IllegalSelectQueryException; import org.hibernate.query.MutationQuery; import org.hibernate.query.Query; +import org.hibernate.query.QueryTypeMismatchException; import org.hibernate.query.SelectionQuery; import org.hibernate.query.UnknownNamedQueryException; import org.hibernate.query.criteria.HibernateCriteriaBuilder; @@ -71,7 +73,7 @@ import org.hibernate.query.sql.spi.NamedNativeQueryMemento; import org.hibernate.query.sql.spi.NativeQueryImplementor; import org.hibernate.query.sqm.SqmSelectionQuery; import org.hibernate.query.sqm.internal.QuerySqmImpl; -import org.hibernate.query.sqm.internal.SqmSelectQueryImpl; +import org.hibernate.query.sqm.internal.SqmSelectionQueryImpl; import org.hibernate.query.sqm.tree.SqmDmlStatement; import org.hibernate.query.sqm.tree.SqmStatement; import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement; @@ -665,7 +667,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont } @Override - public SelectionQuery createSelectQuery(String hqlString) { + public SelectionQuery createSelectQuery(String hqlString) { checkOpen(); pulseTransactionCoordinator(); delayedAfterCompletion(); @@ -682,7 +684,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont throw new IllegalSelectQueryException( "Expecting a selection query, but found `" + hqlString + "`" ); } - final SqmSelectionQuery query = new SqmSelectQueryImpl( hqlString, hqlInterpretation, this ); + final SqmSelectionQuery query = new SqmSelectionQueryImpl<>( hqlString, hqlInterpretation, this ); query.setComment( hqlString ); applyQuerySettingsAndHints( query ); @@ -695,6 +697,27 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont } } + @Override + public SelectionQuery createSelectQuery(String hqlString, Class expectedResultType) { + final SelectionQuery selectQuery = createSelectQuery( hqlString ); + //noinspection unchecked + final Class resultType = ( (SqmSelectionQueryImpl) selectQuery ).getResultType(); + if ( resultType == null || expectedResultType.isAssignableFrom( resultType ) ) { + //noinspection unchecked + return (SelectionQuery) selectQuery; + } + + throw new QueryTypeMismatchException( + String.format( + Locale.ROOT, + "Query result-type error - expecting `%s`, but found `%s`", + expectedResultType.getName(), + resultType.getName() + ) + ); + } + + @Override public QueryImplementor createQuery(String queryString, Class resultClass) { checkOpen(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/Query.java b/hibernate-core/src/main/java/org/hibernate/query/Query.java index 0ceafade5b..84bf1a04e0 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/Query.java +++ b/hibernate-core/src/main/java/org/hibernate/query/Query.java @@ -66,7 +66,7 @@ import jakarta.persistence.TypedQuery; * @param The result type, for typed queries, or {@link Object} for untyped queries */ @Incubating -public interface Query extends SelectionQuery, MutationQuery, TypedQuery { +public interface Query extends SelectionQuery, MutationQuery, TypedQuery { /** * Execute the query and return the query results as a {@link List}. diff --git a/hibernate-core/src/main/java/org/hibernate/query/QueryProducer.java b/hibernate-core/src/main/java/org/hibernate/query/QueryProducer.java index 4fb59d9bde..f5b3341b63 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/QueryProducer.java +++ b/hibernate-core/src/main/java/org/hibernate/query/QueryProducer.java @@ -168,7 +168,19 @@ public interface QueryProducer { * @throws IllegalSelectQueryException if the given HQL query * is an insert, update or delete query */ - SelectionQuery createSelectQuery(String hqlString); + SelectionQuery createSelectQuery(String hqlString); + + /** + * Create a {@link SelectionQuery} reference for the given HQL. + * + * Only valid for select queries + * + * @see jakarta.persistence.EntityManager#createQuery(String) + * + * @throws IllegalSelectQueryException if the given HQL query + * is an insert, update or delete query + */ + SelectionQuery createSelectQuery(String hqlString, Class resultType); /** * Create a MutationQuery reference for the given HQL insert, diff --git a/hibernate-core/src/main/java/org/hibernate/query/SelectionQuery.java b/hibernate-core/src/main/java/org/hibernate/query/SelectionQuery.java index 61a9ee5552..cac1e80bc9 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/SelectionQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/SelectionQuery.java @@ -39,7 +39,7 @@ import jakarta.persistence.TemporalType; * @author Steve Ebersole */ @Incubating -public interface SelectionQuery extends CommonQueryContract { +public interface SelectionQuery extends CommonQueryContract { /** * Execute the query and return the query results as a {@link List}. * If the query contains multiple items in the selection list, then @@ -48,7 +48,7 @@ public interface SelectionQuery extends CommonQueryContract { * * @return the result list */ - List list(); + List list(); /** * Execute the query and return the query results as a {@link List}. @@ -58,7 +58,7 @@ public interface SelectionQuery extends CommonQueryContract { * * @return the results as a list */ - default List getResultList() { + default List getResultList() { return list(); } @@ -70,7 +70,7 @@ public interface SelectionQuery extends CommonQueryContract { * @apiNote The exact behavior of this method depends somewhat * on the JDBC driver's {@link java.sql.ResultSet} scrolling support */ - ScrollableResults scroll(); + ScrollableResults scroll(); /** * Returns scrollable access to the query results. The capabilities of the @@ -79,7 +79,7 @@ public interface SelectionQuery extends CommonQueryContract { * @apiNote The exact behavior of this method depends somewhat * on the JDBC driver's {@link java.sql.ResultSet} scrolling support */ - ScrollableResults scroll(ScrollMode scrollMode); + ScrollableResults scroll(ScrollMode scrollMode); /** * Execute the query and return the query results as a {@link Stream}. @@ -92,7 +92,7 @@ public interface SelectionQuery extends CommonQueryContract { * * @return The results as a {@link Stream} */ - default Stream getResultStream() { + default Stream getResultStream() { return stream(); } @@ -109,7 +109,7 @@ public interface SelectionQuery extends CommonQueryContract { * * @since 5.2 */ - default Stream stream() { + default Stream stream() { return getResultStream(); } @@ -121,7 +121,7 @@ public interface SelectionQuery extends CommonQueryContract { * * @throws NonUniqueResultException if there is more than one matching result */ - Object uniqueResult(); + R uniqueResult(); /** * Execute the query and return the single result of the query, @@ -132,7 +132,7 @@ public interface SelectionQuery extends CommonQueryContract { * @throws jakarta.persistence.NonUniqueResultException if there is more than one matching result * @throws jakarta.persistence.NoResultException if there is no result to return */ - Object getSingleResult(); + R getSingleResult(); /** * Execute the query and return the single result of the query, @@ -142,18 +142,18 @@ public interface SelectionQuery extends CommonQueryContract { * * @throws NonUniqueResultException if there is more than one matching result */ - Optional uniqueResultOptional(); + Optional uniqueResultOptional(); - SelectionQuery setHint(String hintName, Object value); + SelectionQuery setHint(String hintName, Object value); @Override - SelectionQuery setFlushMode(FlushModeType flushMode); + SelectionQuery setFlushMode(FlushModeType flushMode); @Override - SelectionQuery setHibernateFlushMode(FlushMode flushMode); + SelectionQuery setHibernateFlushMode(FlushMode flushMode); @Override - SelectionQuery setTimeout(int timeout); + SelectionQuery setTimeout(int timeout); /** * Obtain the JDBC fetch size hint in effect for this query. This value is eventually passed along to the JDBC @@ -179,7 +179,7 @@ public interface SelectionQuery extends CommonQueryContract { * * @see #getFetchSize() */ - SelectionQuery setFetchSize(int fetchSize); + SelectionQuery setFetchSize(int fetchSize); /** * Should entities and proxies loaded by this Query be put in read-only mode? If the @@ -225,7 +225,7 @@ public interface SelectionQuery extends CommonQueryContract { * are to be put in read-only mode; {@code false} indicates that entities and proxies * loaded by the query will be put in modifiable mode */ - SelectionQuery setReadOnly(boolean readOnly); + SelectionQuery setReadOnly(boolean readOnly); /** * The max number of rows requested for the query results @@ -236,7 +236,7 @@ public interface SelectionQuery extends CommonQueryContract { * Set the max number of rows requested for the query results. Applied * to the SQL query */ - SelectionQuery setMaxResults(int maxResult); + SelectionQuery setMaxResults(int maxResult); /** * The first row position to return from the query results. Applied @@ -248,7 +248,7 @@ public interface SelectionQuery extends CommonQueryContract { * Set the first row position to return from the query results. Applied * to the SQL query */ - SelectionQuery setFirstResult(int startPosition); + SelectionQuery setFirstResult(int startPosition); /** * Obtain the CacheMode in effect for this query. By default, the query @@ -275,7 +275,7 @@ public interface SelectionQuery extends CommonQueryContract { * @see #getCacheMode() * @see Session#setCacheMode */ - SelectionQuery setCacheMode(CacheMode cacheMode); + SelectionQuery setCacheMode(CacheMode cacheMode); /** * Should the results of the query be stored in the second level cache? @@ -296,7 +296,7 @@ public interface SelectionQuery extends CommonQueryContract { * * @see #isCacheable */ - SelectionQuery setCacheable(boolean cacheable); + SelectionQuery setCacheable(boolean cacheable); /** * Obtain the name of the second level query cache region in which query results will be stored (if they are @@ -311,7 +311,7 @@ public interface SelectionQuery extends CommonQueryContract { * * @see #getCacheRegion() */ - SelectionQuery setCacheRegion(String cacheRegion); + SelectionQuery setCacheRegion(String cacheRegion); /** * The LockOptions currently in effect for the query @@ -323,134 +323,134 @@ public interface SelectionQuery extends CommonQueryContract { * * @see #setHibernateLockMode */ - SelectionQuery setLockMode(LockModeType lockMode); + SelectionQuery setLockMode(LockModeType lockMode); /** * Specify the root LockMode for the query */ - SelectionQuery setHibernateLockMode(LockMode lockMode); + SelectionQuery setHibernateLockMode(LockMode lockMode); /** * Specify a LockMode to apply to a specific alias defined in the query */ - SelectionQuery setAliasSpecificLockMode(String alias, LockMode lockMode); + SelectionQuery setAliasSpecificLockMode(String alias, LockMode lockMode); /** * Specifies whether follow-on locking should be applied? */ - SelectionQuery setFollowOnLocking(boolean enable); + SelectionQuery setFollowOnLocking(boolean enable); @Override - SelectionQuery setParameter(String name, Object value); + SelectionQuery setParameter(String name, Object value); @Override -

SelectionQuery setParameter(String name, P value, Class

type); +

SelectionQuery setParameter(String name, P value, Class

type); @Override -

SelectionQuery setParameter(String name, P value, BindableType

type); +

SelectionQuery setParameter(String name, P value, BindableType

type); @Override - SelectionQuery setParameter(String name, Instant value, TemporalType temporalType); + SelectionQuery setParameter(String name, Instant value, TemporalType temporalType); @Override - SelectionQuery setParameter(String name, Calendar value, TemporalType temporalType); + SelectionQuery setParameter(String name, Calendar value, TemporalType temporalType); @Override - SelectionQuery setParameter(String name, Date value, TemporalType temporalType); + SelectionQuery setParameter(String name, Date value, TemporalType temporalType); @Override - SelectionQuery setParameter(int position, Object value); + SelectionQuery setParameter(int position, Object value); @Override -

SelectionQuery setParameter(int position, P value, Class

type); +

SelectionQuery setParameter(int position, P value, Class

type); @Override -

SelectionQuery setParameter(int position, P value, BindableType

type); +

SelectionQuery setParameter(int position, P value, BindableType

type); @Override - SelectionQuery setParameter(int position, Instant value, TemporalType temporalType); + SelectionQuery setParameter(int position, Instant value, TemporalType temporalType); @Override - SelectionQuery setParameter(int position, Date value, TemporalType temporalType); + SelectionQuery setParameter(int position, Date value, TemporalType temporalType); @Override - SelectionQuery setParameter(int position, Calendar value, TemporalType temporalType); + SelectionQuery setParameter(int position, Calendar value, TemporalType temporalType); @Override - SelectionQuery setParameter(QueryParameter parameter, T value); + SelectionQuery setParameter(QueryParameter parameter, T value); @Override -

SelectionQuery setParameter(QueryParameter

parameter, P value, Class

type); +

SelectionQuery setParameter(QueryParameter

parameter, P value, Class

type); @Override -

SelectionQuery setParameter(QueryParameter

parameter, P val, BindableType

type); +

SelectionQuery setParameter(QueryParameter

parameter, P val, BindableType

type); @Override - SelectionQuery setParameter(Parameter param, T value); + SelectionQuery setParameter(Parameter param, T value); @Override - SelectionQuery setParameter(Parameter param, Calendar value, TemporalType temporalType); + SelectionQuery setParameter(Parameter param, Calendar value, TemporalType temporalType); @Override - SelectionQuery setParameter(Parameter param, Date value, TemporalType temporalType); + SelectionQuery setParameter(Parameter param, Date value, TemporalType temporalType); @Override - SelectionQuery setParameterList(String name, Collection values); + SelectionQuery setParameterList(String name, Collection values); @Override -

SelectionQuery setParameterList(String name, Collection values, Class

javaType); +

SelectionQuery setParameterList(String name, Collection values, Class

javaType); @Override -

SelectionQuery setParameterList(String name, Collection values, BindableType

type); +

SelectionQuery setParameterList(String name, Collection values, BindableType

type); @Override - SelectionQuery setParameterList(String name, Object[] values); + SelectionQuery setParameterList(String name, Object[] values); @Override -

SelectionQuery setParameterList(String name, P[] values, Class

javaType); +

SelectionQuery setParameterList(String name, P[] values, Class

javaType); @Override -

SelectionQuery setParameterList(String name, P[] values, BindableType

type); +

SelectionQuery setParameterList(String name, P[] values, BindableType

type); @Override - SelectionQuery setParameterList(int position, Collection values); + SelectionQuery setParameterList(int position, Collection values); @Override -

SelectionQuery setParameterList(int position, Collection values, Class

javaType); +

SelectionQuery setParameterList(int position, Collection values, Class

javaType); @Override -

SelectionQuery setParameterList(int position, Collection values, BindableType

type); +

SelectionQuery setParameterList(int position, Collection values, BindableType

type); @Override - SelectionQuery setParameterList(int position, Object[] values); + SelectionQuery setParameterList(int position, Object[] values); @Override -

SelectionQuery setParameterList(int position, P[] values, Class

javaType); +

SelectionQuery setParameterList(int position, P[] values, Class

javaType); @Override -

SelectionQuery setParameterList(int position, P[] values, BindableType

type); +

SelectionQuery setParameterList(int position, P[] values, BindableType

type); @Override -

SelectionQuery setParameterList(QueryParameter

parameter, Collection values); +

SelectionQuery setParameterList(QueryParameter

parameter, Collection values); @Override -

SelectionQuery setParameterList(QueryParameter

parameter, Collection values, Class

javaType); +

SelectionQuery setParameterList(QueryParameter

parameter, Collection values, Class

javaType); @Override -

SelectionQuery setParameterList(QueryParameter

parameter, Collection values, BindableType

type); +

SelectionQuery setParameterList(QueryParameter

parameter, Collection values, BindableType

type); @Override -

SelectionQuery setParameterList(QueryParameter

parameter, P[] values); +

SelectionQuery setParameterList(QueryParameter

parameter, P[] values); @Override -

SelectionQuery setParameterList(QueryParameter

parameter, P[] values, Class

javaType); +

SelectionQuery setParameterList(QueryParameter

parameter, P[] values, Class

javaType); @Override -

SelectionQuery setParameterList(QueryParameter

parameter, P[] values, BindableType

type); +

SelectionQuery setParameterList(QueryParameter

parameter, P[] values, BindableType

type); @Override - SelectionQuery setProperties(Object bean); + SelectionQuery setProperties(Object bean); @Override - SelectionQuery setProperties(@SuppressWarnings("rawtypes") Map bean); + SelectionQuery setProperties(@SuppressWarnings("rawtypes") Map bean); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java index 88e770b743..0453f0a494 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java @@ -34,7 +34,6 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.EntityManagerMessageLogger; import org.hibernate.internal.HEMLogging; import org.hibernate.jpa.AvailableHints; -import org.hibernate.jpa.internal.util.ConfigurationHelper; import org.hibernate.jpa.internal.util.FlushModeTypeHelper; import org.hibernate.jpa.internal.util.LockModeTypeHelper; import org.hibernate.metamodel.model.domain.ManagedDomainType; @@ -77,8 +76,6 @@ import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_LOCK_TIMEOUT; import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_QUERY_TIMEOUT; import static org.hibernate.jpa.SpecHints.HINT_SPEC_CACHE_RETRIEVE_MODE; import static org.hibernate.jpa.SpecHints.HINT_SPEC_CACHE_STORE_MODE; -import static org.hibernate.jpa.SpecHints.HINT_SPEC_FETCH_GRAPH; -import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOAD_GRAPH; import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOCK_SCOPE; import static org.hibernate.jpa.SpecHints.HINT_SPEC_LOCK_TIMEOUT; import static org.hibernate.jpa.SpecHints.HINT_SPEC_QUERY_TIMEOUT; @@ -87,7 +84,7 @@ import static org.hibernate.jpa.SpecHints.HINT_SPEC_QUERY_TIMEOUT; * @author Steve Ebersole */ public abstract class AbstractQuery - extends AbstractSelectionQuery + extends AbstractSelectionQuery implements QueryImplementor { protected static final EntityManagerMessageLogger log = HEMLogging.messageLogger( AbstractQuery.class ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java index 6272fff8fa..f4328fc469 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java @@ -59,9 +59,9 @@ import static org.hibernate.jpa.QueryHints.HINT_READONLY; /** * @author Steve Ebersole */ -public abstract class AbstractSelectionQuery +public abstract class AbstractSelectionQuery extends AbstractCommonQueryContract - implements SelectionQuery, DomainQueryExecutionContext { + implements SelectionQuery, DomainQueryExecutionContext { private Callback callback; @@ -115,11 +115,11 @@ public abstract class AbstractSelectionQuery private CacheMode sessionCacheMode; @Override - public List list() { + public List list() { beforeQuery(); boolean success = false; try { - final List result = doList(); + final List result = doList(); success = true; return result; } @@ -180,19 +180,19 @@ public abstract class AbstractSelectionQuery return lockMode != null && lockMode.greaterThan( LockMode.READ ); } - protected abstract List doList(); + protected abstract List doList(); @Override - public ScrollableResultsImplementor scroll() { + public ScrollableResultsImplementor scroll() { return scroll( getSession().getFactory().getJdbcServices().getJdbcEnvironment().getDialect().defaultScrollMode() ); } @Override - public ScrollableResultsImplementor scroll(ScrollMode scrollMode) { + public ScrollableResultsImplementor scroll(ScrollMode scrollMode) { return doScroll( scrollMode ); } - protected abstract ScrollableResultsImplementor doScroll(ScrollMode scrollMode); + protected abstract ScrollableResultsImplementor doScroll(ScrollMode scrollMode); @SuppressWarnings( {"unchecked", "rawtypes"} ) @Override @@ -206,14 +206,14 @@ public abstract class AbstractSelectionQuery } @Override - public Object uniqueResult() { + public R uniqueResult() { return uniqueElement( list() ); } @Override - public Object getSingleResult() { + public R getSingleResult() { try { - final List list = list(); + final List list = list(); if ( list.isEmpty() ) { throw new NoResultException( "No result found for query" ); } @@ -225,12 +225,12 @@ public abstract class AbstractSelectionQuery } @SuppressWarnings("WeakerAccess") - protected static Object uniqueElement(List list) throws NonUniqueResultException { + protected static T uniqueElement(List list) throws NonUniqueResultException { int size = list.size(); if ( size == 0 ) { return null; } - final Object first = list.get( 0 ); + final T first = list.get( 0 ); // todo (6.0) : add a setting here to control whether to perform this validation or not for ( int i = 1; i < size; i++ ) { if ( list.get( i ) != first ) { @@ -240,9 +240,8 @@ public abstract class AbstractSelectionQuery return first; } - @SuppressWarnings("rawtypes") @Override - public Optional uniqueResultOptional() { + public Optional uniqueResultOptional() { return Optional.ofNullable( uniqueResult() ); } @@ -279,13 +278,13 @@ public abstract class AbstractSelectionQuery } @Override - public SelectionQuery setFlushMode(FlushModeType flushMode) { + public SelectionQuery setFlushMode(FlushModeType flushMode) { getQueryOptions().setFlushMode( FlushMode.fromJpaFlushMode( flushMode ) ); return this; } @Override - public SelectionQuery setMaxResults(int maxResult) { + public SelectionQuery setMaxResults(int maxResult) { if ( maxResult < 0 ) { throw new IllegalArgumentException( "max-results cannot be negative" ); } @@ -298,12 +297,12 @@ public abstract class AbstractSelectionQuery } @Override - public SelectionQuery setFirstResult(int startPosition) { + public SelectionQuery setFirstResult(int startPosition) { return null; } @Override - public SelectionQuery setHint(String hintName, Object value) { + public SelectionQuery setHint(String hintName, Object value) { super.setHint( hintName, value ); return this; } @@ -319,7 +318,7 @@ public abstract class AbstractSelectionQuery * * @see #setHibernateLockMode */ - public SelectionQuery setLockMode(LockModeType lockMode) { + public SelectionQuery setLockMode(LockModeType lockMode) { setHibernateLockMode( LockModeTypeHelper.getLockMode( lockMode ) ); return this; } @@ -327,7 +326,7 @@ public abstract class AbstractSelectionQuery /** * Specify the root LockMode for the query */ - public SelectionQuery setHibernateLockMode(LockMode lockMode) { + public SelectionQuery setHibernateLockMode(LockMode lockMode) { getLockOptions().setLockMode( lockMode ); return this; } @@ -335,7 +334,7 @@ public abstract class AbstractSelectionQuery /** * Specify a LockMode to apply to a specific alias defined in the query */ - public SelectionQuery setAliasSpecificLockMode(String alias, LockMode lockMode) { + public SelectionQuery setAliasSpecificLockMode(String alias, LockMode lockMode) { getLockOptions().setAliasSpecificLockMode( alias, lockMode ); return this; } @@ -343,7 +342,7 @@ public abstract class AbstractSelectionQuery /** * Specifies whether follow-on locking should be applied? */ - public SelectionQuery setFollowOnLocking(boolean enable) { + public SelectionQuery setFollowOnLocking(boolean enable) { getLockOptions().setFollowOnLocking( enable ); return this; } @@ -385,7 +384,7 @@ public abstract class AbstractSelectionQuery } @Override - public SelectionQuery setFetchSize(int fetchSize) { + public SelectionQuery setFetchSize(int fetchSize) { getQueryOptions().setFetchSize( fetchSize ); return this; } @@ -398,7 +397,7 @@ public abstract class AbstractSelectionQuery } @Override - public SelectionQuery setReadOnly(boolean readOnly) { + public SelectionQuery setReadOnly(boolean readOnly) { getQueryOptions().setReadOnly( readOnly ); return this; } @@ -408,7 +407,7 @@ public abstract class AbstractSelectionQuery } @Override - public SelectionQuery setCacheMode(CacheMode cacheMode) { + public SelectionQuery setCacheMode(CacheMode cacheMode) { getQueryOptions().setCacheMode( cacheMode ); return this; } @@ -419,7 +418,7 @@ public abstract class AbstractSelectionQuery } @Override - public SelectionQuery setCacheable(boolean cacheable) { + public SelectionQuery setCacheable(boolean cacheable) { getQueryOptions().setResultCachingEnabled( cacheable ); return this; } @@ -430,7 +429,7 @@ public abstract class AbstractSelectionQuery } @Override - public SelectionQuery setCacheRegion(String regionName) { + public SelectionQuery setCacheRegion(String regionName) { getQueryOptions().setResultCacheRegionName( regionName ); return this; } @@ -440,242 +439,242 @@ public abstract class AbstractSelectionQuery // covariance @Override - public SelectionQuery setHibernateFlushMode(FlushMode flushMode) { + public SelectionQuery setHibernateFlushMode(FlushMode flushMode) { super.setHibernateFlushMode( flushMode ); return this; } @Override - public SelectionQuery setTimeout(int timeout) { + public SelectionQuery setTimeout(int timeout) { super.setTimeout( timeout ); return this; } @Override - public SelectionQuery setParameter(String name, Object value) { + public SelectionQuery setParameter(String name, Object value) { super.setParameter( name, value ); return this; } @Override - public

SelectionQuery setParameter(String name, P value, Class

javaType) { + public

SelectionQuery setParameter(String name, P value, Class

javaType) { super.setParameter( name, value, javaType ); return this; } @Override - public

SelectionQuery setParameter(String name, P value, BindableType

type) { + public

SelectionQuery setParameter(String name, P value, BindableType

type) { super.setParameter( name, value, type ); return this; } @Override - public SelectionQuery setParameter(String name, Instant value, TemporalType temporalType) { + public SelectionQuery setParameter(String name, Instant value, TemporalType temporalType) { super.setParameter( name, value, temporalType ); return this; } @Override - public SelectionQuery setParameter(int position, Object value) { + public SelectionQuery setParameter(int position, Object value) { super.setParameter( position, value ); return this; } @Override - public

SelectionQuery setParameter(int position, P value, Class

javaType) { + public

SelectionQuery setParameter(int position, P value, Class

javaType) { super.setParameter( position, value, javaType ); return this; } @Override - public

SelectionQuery setParameter(int position, P value, BindableType

type) { + public

SelectionQuery setParameter(int position, P value, BindableType

type) { super.setParameter( position, value, type ); return this; } @Override - public SelectionQuery setParameter(int position, Instant value, TemporalType temporalType) { + public SelectionQuery setParameter(int position, Instant value, TemporalType temporalType) { super.setParameter( position, value, temporalType ); return this; } @Override - public

SelectionQuery setParameter(QueryParameter

parameter, P value) { + public

SelectionQuery setParameter(QueryParameter

parameter, P value) { super.setParameter( parameter, value ); return this; } @Override - public

SelectionQuery setParameter(QueryParameter

parameter, P value, Class

javaType) { + public

SelectionQuery setParameter(QueryParameter

parameter, P value, Class

javaType) { super.setParameter( parameter, value, javaType ); return this; } @Override - public

SelectionQuery setParameter(QueryParameter

parameter, P value, BindableType

type) { + public

SelectionQuery setParameter(QueryParameter

parameter, P value, BindableType

type) { super.setParameter( parameter, value, type ); return this; } @Override - public

SelectionQuery setParameter(Parameter

parameter, P value) { + public

SelectionQuery setParameter(Parameter

parameter, P value) { super.setParameter( parameter, value ); return this; } @Override - public SelectionQuery setParameter(Parameter param, Calendar value, TemporalType temporalType) { + public SelectionQuery setParameter(Parameter param, Calendar value, TemporalType temporalType) { super.setParameter( param, value, temporalType ); return this; } @Override - public SelectionQuery setParameter(Parameter param, Date value, TemporalType temporalType) { + public SelectionQuery setParameter(Parameter param, Date value, TemporalType temporalType) { super.setParameter( param, value, temporalType ); return this; } @Override - public SelectionQuery setParameter(String name, Calendar value, TemporalType temporalType) { + public SelectionQuery setParameter(String name, Calendar value, TemporalType temporalType) { super.setParameter( name, value, temporalType ); return this; } @Override - public SelectionQuery setParameter(String name, Date value, TemporalType temporalType) { + public SelectionQuery setParameter(String name, Date value, TemporalType temporalType) { super.setParameter( name, value, temporalType ); return this; } @Override - public SelectionQuery setParameter(int position, Calendar value, TemporalType temporalType) { + public SelectionQuery setParameter(int position, Calendar value, TemporalType temporalType) { super.setParameter( position, value, temporalType ); return this; } @Override - public SelectionQuery setParameter(int position, Date value, TemporalType temporalType) { + public SelectionQuery setParameter(int position, Date value, TemporalType temporalType) { super.setParameter( position, value, temporalType ); return this; } @Override - public SelectionQuery setParameterList(String name, Collection values) { + public SelectionQuery setParameterList(String name, Collection values) { super.setParameterList( name, values ); return this; } @Override - public

SelectionQuery setParameterList(String name, Collection values, Class

javaType) { + public

SelectionQuery setParameterList(String name, Collection values, Class

javaType) { super.setParameterList( name, values, javaType ); return this; } @Override - public

SelectionQuery setParameterList(String name, Collection values, BindableType

type) { + public

SelectionQuery setParameterList(String name, Collection values, BindableType

type) { super.setParameterList( name, values, type ); return this; } @Override - public SelectionQuery setParameterList(String name, Object[] values) { + public SelectionQuery setParameterList(String name, Object[] values) { super.setParameterList( name, values ); return this; } @Override - public

SelectionQuery setParameterList(String name, P[] values, Class

javaType) { + public

SelectionQuery setParameterList(String name, P[] values, Class

javaType) { super.setParameterList( name, values, javaType ); return this; } @Override - public

SelectionQuery setParameterList(String name, P[] values, BindableType

type) { + public

SelectionQuery setParameterList(String name, P[] values, BindableType

type) { super.setParameterList( name, values, type ); return this; } @Override - public SelectionQuery setParameterList(int position, Collection values) { + public SelectionQuery setParameterList(int position, Collection values) { super.setParameterList( position, values ); return this; } @Override - public

SelectionQuery setParameterList(int position, Collection values, Class

javaType) { + public

SelectionQuery setParameterList(int position, Collection values, Class

javaType) { super.setParameterList( position, values, javaType ); return this; } @Override - public

SelectionQuery setParameterList(int position, Collection values, BindableType

type) { + public

SelectionQuery setParameterList(int position, Collection values, BindableType

type) { super.setParameterList( position, values, type ); return this; } @Override - public SelectionQuery setParameterList(int position, Object[] values) { + public SelectionQuery setParameterList(int position, Object[] values) { super.setParameterList( position, values ); return this; } @Override - public

SelectionQuery setParameterList(int position, P[] values, Class

javaType) { + public

SelectionQuery setParameterList(int position, P[] values, Class

javaType) { super.setParameterList( position, values, javaType ); return this; } @Override - public

SelectionQuery setParameterList(int position, P[] values, BindableType

type) { + public

SelectionQuery setParameterList(int position, P[] values, BindableType

type) { super.setParameterList( position, values, type ); return this; } @Override - public

SelectionQuery setParameterList(QueryParameter

parameter, Collection values) { + public

SelectionQuery setParameterList(QueryParameter

parameter, Collection values) { super.setParameterList( parameter, values ); return this; } @Override - public

SelectionQuery setParameterList(QueryParameter

parameter, Collection values, Class

javaType) { + public

SelectionQuery setParameterList(QueryParameter

parameter, Collection values, Class

javaType) { super.setParameterList( parameter, values, javaType ); return this; } @Override - public

SelectionQuery setParameterList(QueryParameter

parameter, Collection values, BindableType

type) { + public

SelectionQuery setParameterList(QueryParameter

parameter, Collection values, BindableType

type) { super.setParameterList( parameter, values, type ); return this; } @Override - public

SelectionQuery setParameterList(QueryParameter

parameter, P[] values) { + public

SelectionQuery setParameterList(QueryParameter

parameter, P[] values) { super.setParameterList( parameter, values ); return this; } @Override - public

SelectionQuery setParameterList(QueryParameter

parameter, P[] values, Class

javaType) { + public

SelectionQuery setParameterList(QueryParameter

parameter, P[] values, Class

javaType) { super.setParameterList( parameter, values, javaType ); return this; } @Override - public

SelectionQuery setParameterList(QueryParameter

parameter, P[] values, BindableType

type) { + public

SelectionQuery setParameterList(QueryParameter

parameter, P[] values, BindableType

type) { super.setParameterList( parameter, values, type ); return this; } @Override - public SelectionQuery setProperties(Map map) { + public SelectionQuery setProperties(Map map) { super.setProperties( map ); return this; } @Override - public SelectionQuery setProperties(Object bean) { + public SelectionQuery setProperties(Object bean) { super.setProperties( bean ); return this; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java index 9a7c5fa3be..81f7036448 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java @@ -40,7 +40,6 @@ import org.hibernate.internal.AbstractSharedSessionContract; import org.hibernate.internal.util.MathHelper; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.jpa.internal.util.LockModeTypeHelper; import org.hibernate.jpa.spi.NativeQueryTupleTransformer; import org.hibernate.metamodel.model.domain.BasicDomainType; import org.hibernate.query.BindableType; @@ -101,7 +100,6 @@ import jakarta.persistence.Tuple; import jakarta.persistence.metamodel.SingularAttribute; import static org.hibernate.jpa.HibernateHints.HINT_NATIVE_LOCK_MODE; -import static org.hibernate.jpa.QueryHints.HINT_NATIVE_SPACES; /** * @author Steve Ebersole diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/SqmSelectionQuery.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/SqmSelectionQuery.java index 894436bdbf..a4b450f5c5 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/SqmSelectionQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/SqmSelectionQuery.java @@ -25,140 +25,140 @@ import jakarta.persistence.TemporalType; /** * @author Steve Ebersole */ -public interface SqmSelectionQuery extends SqmQuery, SelectionQuery { +public interface SqmSelectionQuery extends SqmQuery, SelectionQuery { @Override - SqmSelectionQuery setParameter(String name, Object value); + SqmSelectionQuery setParameter(String name, Object value); @Override -

SqmSelectionQuery setParameter(String name, P value, Class

type); +

SqmSelectionQuery setParameter(String name, P value, Class

type); @Override -

SqmSelectionQuery setParameter(String name, P value, BindableType

type); +

SqmSelectionQuery setParameter(String name, P value, BindableType

type); @Override - SqmSelectionQuery setParameter(String name, Instant value, TemporalType temporalType); + SqmSelectionQuery setParameter(String name, Instant value, TemporalType temporalType); @Override - SqmSelectionQuery setParameter(String name, Calendar value, TemporalType temporalType); + SqmSelectionQuery setParameter(String name, Calendar value, TemporalType temporalType); @Override - SqmSelectionQuery setParameter(String name, Date value, TemporalType temporalType); + SqmSelectionQuery setParameter(String name, Date value, TemporalType temporalType); @Override - SqmSelectionQuery setParameter(int position, Object value); + SqmSelectionQuery setParameter(int position, Object value); @Override -

SqmSelectionQuery setParameter(int position, P value, Class

type); +

SqmSelectionQuery setParameter(int position, P value, Class

type); @Override -

SqmSelectionQuery setParameter(int position, P value, BindableType

type); +

SqmSelectionQuery setParameter(int position, P value, BindableType

type); @Override - SqmSelectionQuery setParameter(int position, Instant value, TemporalType temporalType); + SqmSelectionQuery setParameter(int position, Instant value, TemporalType temporalType); @Override - SqmSelectionQuery setParameter(int position, Date value, TemporalType temporalType); + SqmSelectionQuery setParameter(int position, Date value, TemporalType temporalType); @Override - SqmSelectionQuery setParameter(int position, Calendar value, TemporalType temporalType); + SqmSelectionQuery setParameter(int position, Calendar value, TemporalType temporalType); @Override - SqmSelectionQuery setParameter(QueryParameter parameter, T value); + SqmSelectionQuery setParameter(QueryParameter parameter, T value); @Override -

SqmSelectionQuery setParameter(QueryParameter

parameter, P value, Class

type); +

SqmSelectionQuery setParameter(QueryParameter

parameter, P value, Class

type); @Override -

SqmSelectionQuery setParameter(QueryParameter

parameter, P val, BindableType

type); +

SqmSelectionQuery setParameter(QueryParameter

parameter, P val, BindableType

type); @Override - SqmSelectionQuery setParameter(Parameter param, T value); + SqmSelectionQuery setParameter(Parameter param, T value); @Override - SqmSelectionQuery setParameter(Parameter param, Calendar value, TemporalType temporalType); + SqmSelectionQuery setParameter(Parameter param, Calendar value, TemporalType temporalType); @Override - SqmSelectionQuery setParameter(Parameter param, Date value, TemporalType temporalType); + SqmSelectionQuery setParameter(Parameter param, Date value, TemporalType temporalType); @Override - SqmSelectionQuery setParameterList(String name, Collection values); + SqmSelectionQuery setParameterList(String name, Collection values); @Override -

SqmSelectionQuery setParameterList(String name, Collection values, Class

javaType); +

SqmSelectionQuery setParameterList(String name, Collection values, Class

javaType); @Override -

SqmSelectionQuery setParameterList(String name, Collection values, BindableType

type); +

SqmSelectionQuery setParameterList(String name, Collection values, BindableType

type); @Override - SqmSelectionQuery setParameterList(String name, Object[] values); + SqmSelectionQuery setParameterList(String name, Object[] values); @Override -

SqmSelectionQuery setParameterList(String name, P[] values, Class

javaType); +

SqmSelectionQuery setParameterList(String name, P[] values, Class

javaType); @Override -

SqmSelectionQuery setParameterList(String name, P[] values, BindableType

type); +

SqmSelectionQuery setParameterList(String name, P[] values, BindableType

type); @Override - SqmSelectionQuery setParameterList(int position, Collection values); + SqmSelectionQuery setParameterList(int position, Collection values); @Override -

SqmSelectionQuery setParameterList(int position, Collection values, Class

javaType); +

SqmSelectionQuery setParameterList(int position, Collection values, Class

javaType); @Override -

SqmSelectionQuery setParameterList(int position, Collection values, BindableType

type); +

SqmSelectionQuery setParameterList(int position, Collection values, BindableType

type); @Override - SqmSelectionQuery setParameterList(int position, Object[] values); + SqmSelectionQuery setParameterList(int position, Object[] values); @Override -

SqmSelectionQuery setParameterList(int position, P[] values, Class

javaType); +

SqmSelectionQuery setParameterList(int position, P[] values, Class

javaType); @Override -

SqmSelectionQuery setParameterList(int position, P[] values, BindableType

type); +

SqmSelectionQuery setParameterList(int position, P[] values, BindableType

type); @Override -

SqmSelectionQuery setParameterList(QueryParameter

parameter, Collection values); +

SqmSelectionQuery setParameterList(QueryParameter

parameter, Collection values); @Override -

SqmSelectionQuery setParameterList(QueryParameter

parameter, Collection values, Class

javaType); +

SqmSelectionQuery setParameterList(QueryParameter

parameter, Collection values, Class

javaType); @Override -

SqmSelectionQuery setParameterList(QueryParameter

parameter, Collection values, BindableType

type); +

SqmSelectionQuery setParameterList(QueryParameter

parameter, Collection values, BindableType

type); @Override -

SqmSelectionQuery setParameterList(QueryParameter

parameter, P[] values); +

SqmSelectionQuery setParameterList(QueryParameter

parameter, P[] values); @Override -

SqmSelectionQuery setParameterList(QueryParameter

parameter, P[] values, Class

javaType); +

SqmSelectionQuery setParameterList(QueryParameter

parameter, P[] values, Class

javaType); @Override -

SqmSelectionQuery setParameterList(QueryParameter

parameter, P[] values, BindableType

type); +

SqmSelectionQuery setParameterList(QueryParameter

parameter, P[] values, BindableType

type); @Override - SqmSelectionQuery setProperties(Object bean); + SqmSelectionQuery setProperties(Object bean); @Override - SqmSelectionQuery setProperties(Map bean); + SqmSelectionQuery setProperties(Map bean); @Override - SqmSelectionQuery setHibernateFlushMode(FlushMode flushMode); + SqmSelectionQuery setHibernateFlushMode(FlushMode flushMode); @Override - SqmSelectionQuery setCacheMode(CacheMode cacheMode); + SqmSelectionQuery setCacheMode(CacheMode cacheMode); @Override - SqmSelectionQuery setCacheable(boolean cacheable); + SqmSelectionQuery setCacheable(boolean cacheable); @Override - SqmSelectionQuery setCacheRegion(String cacheRegion); + SqmSelectionQuery setCacheRegion(String cacheRegion); @Override - SqmSelectionQuery setTimeout(int timeout); + SqmSelectionQuery setTimeout(int timeout); @Override - SqmSelectionQuery setFetchSize(int fetchSize); + SqmSelectionQuery setFetchSize(int fetchSize); @Override - SqmSelectionQuery setReadOnly(boolean readOnly); + SqmSelectionQuery setReadOnly(boolean readOnly); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java index 1cf89470d8..4a9c3aff98 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java @@ -107,16 +107,16 @@ import jakarta.persistence.PersistenceException; import jakarta.persistence.TemporalType; import jakarta.persistence.Tuple; -import static org.hibernate.cfg.AvailableSettings.JAKARTA_SHARED_CACHE_RETRIEVE_MODE; -import static org.hibernate.cfg.AvailableSettings.JAKARTA_SHARED_CACHE_STORE_MODE; -import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE; -import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_STORE_MODE; -import static org.hibernate.jpa.QueryHints.HINT_CACHEABLE; -import static org.hibernate.jpa.QueryHints.HINT_CACHE_MODE; -import static org.hibernate.jpa.QueryHints.HINT_CACHE_REGION; -import static org.hibernate.jpa.QueryHints.HINT_FETCH_SIZE; -import static org.hibernate.jpa.QueryHints.HINT_FOLLOW_ON_LOCKING; -import static org.hibernate.jpa.QueryHints.HINT_READONLY; +import static org.hibernate.jpa.HibernateHints.HINT_CACHEABLE; +import static org.hibernate.jpa.HibernateHints.HINT_CACHE_MODE; +import static org.hibernate.jpa.HibernateHints.HINT_CACHE_REGION; +import static org.hibernate.jpa.HibernateHints.HINT_FETCH_SIZE; +import static org.hibernate.jpa.HibernateHints.HINT_FOLLOW_ON_LOCKING; +import static org.hibernate.jpa.HibernateHints.HINT_READ_ONLY; +import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_CACHE_RETRIEVE_MODE; +import static org.hibernate.jpa.LegacySpecHints.HINT_JAVAEE_CACHE_STORE_MODE; +import static org.hibernate.jpa.SpecHints.HINT_SPEC_CACHE_RETRIEVE_MODE; +import static org.hibernate.jpa.SpecHints.HINT_SPEC_CACHE_STORE_MODE; import static org.hibernate.query.spi.SqlOmittingQueryOptions.omitSqlQueryOptions; import static org.hibernate.query.sqm.internal.SqmUtil.isSelect; @@ -126,7 +126,7 @@ import static org.hibernate.query.sqm.internal.SqmUtil.isSelect; * @author Steve Ebersole */ public class QuerySqmImpl - extends AbstractSelectionQuery + extends AbstractSelectionQuery implements SqmQueryImplementor, InterpretationsKeySource, DomainQueryExecutionContext { /** @@ -603,7 +603,7 @@ public class QuerySqmImpl } } - protected List doList() { + protected List doList() { verifySelect(); getSession().prepareForQueryExecution( requiresTxn( getQueryOptions().getLockOptions().findGreatestLockMode() ) ); @@ -645,7 +645,7 @@ public class QuerySqmImpl executionContextToUse = this; } - final List list = resolveSelectQueryPlan().performList( executionContextToUse ); + final List list = resolveSelectQueryPlan().performList( executionContextToUse ); if ( needsDistinct ) { int includedCount = -1; @@ -656,9 +656,9 @@ public class QuerySqmImpl final int max = !hasLimit || getQueryOptions().getLimit().getMaxRows() == null ? getMaxRows( sqmStatement, list.size() ) : getQueryOptions().getLimit().getMaxRows(); - final List tmp = new ArrayList<>( list.size() ); + final List tmp = new ArrayList<>( list.size() ); final IdentitySet distinction = new IdentitySet<>( list.size() ); - for ( final Object result : list ) { + for ( final R result : list ) { if ( !distinction.add( result ) ) { continue; } @@ -687,7 +687,7 @@ public class QuerySqmImpl // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Select query plan - private SelectQueryPlan resolveSelectQueryPlan() { + private SelectQueryPlan resolveSelectQueryPlan() { final QueryInterpretationCache.Key cacheKey = SqmInterpretationsKey.createInterpretationsKey( this ); if ( cacheKey != null ) { return getSession().getFactory().getQueryEngine().getInterpretationCache().resolveSelectQueryPlan( @@ -700,9 +700,9 @@ public class QuerySqmImpl } } - private SelectQueryPlan buildSelectQueryPlan() { - final SqmSelectStatement[] concreteSqmStatements = QuerySplitter.split( - (SqmSelectStatement) getSqmStatement(), + private SelectQueryPlan buildSelectQueryPlan() { + final SqmSelectStatement[] concreteSqmStatements = QuerySplitter.split( + (SqmSelectStatement) getSqmStatement(), getSession().getFactory() ); @@ -714,8 +714,9 @@ public class QuerySqmImpl } } - private SelectQueryPlan buildAggregatedSelectQueryPlan(SqmSelectStatement[] concreteSqmStatements) { - final SelectQueryPlan[] aggregatedQueryPlans = new SelectQueryPlan[ concreteSqmStatements.length ]; + private SelectQueryPlan buildAggregatedSelectQueryPlan(SqmSelectStatement[] concreteSqmStatements) { + //noinspection unchecked + final SelectQueryPlan[] aggregatedQueryPlans = new SelectQueryPlan[ concreteSqmStatements.length ]; // todo (6.0) : we want to make sure that certain thing (ResultListTransformer, etc) only get applied at the aggregator-level @@ -727,12 +728,12 @@ public class QuerySqmImpl ); } - return new AggregatedSelectQueryPlanImpl( aggregatedQueryPlans ); + return new AggregatedSelectQueryPlanImpl<>( aggregatedQueryPlans ); } - private SelectQueryPlan buildConcreteSelectQueryPlan( + private SelectQueryPlan buildConcreteSelectQueryPlan( SqmSelectStatement concreteSqmStatement, - Class resultType, + Class resultType, QueryOptions queryOptions) { return new ConcreteSqmSelectQueryPlan<>( concreteSqmStatement, @@ -1000,7 +1001,7 @@ public class QuerySqmImpl super.collectHints( hints ); if ( isReadOnly() ) { - hints.put( HINT_READONLY, true ); + hints.put( HINT_READ_ONLY, true ); } putIfNotNull( hints, HINT_FETCH_SIZE, getFetchSize() ); @@ -1008,14 +1009,12 @@ public class QuerySqmImpl if ( isCacheable() ) { hints.put( HINT_CACHEABLE, true ); putIfNotNull( hints, HINT_CACHE_REGION, getCacheRegion() ); - putIfNotNull( hints, HINT_CACHE_MODE, getCacheMode() ); - putIfNotNull( hints, JAKARTA_SHARED_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() ); - putIfNotNull( hints, JAKARTA_SHARED_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() ); - //noinspection deprecation - putIfNotNull( hints, JPA_SHARED_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() ); - //noinspection deprecation - putIfNotNull( hints, JPA_SHARED_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() ); + + putIfNotNull( hints, HINT_SPEC_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() ); + putIfNotNull( hints, HINT_SPEC_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() ); + putIfNotNull( hints, HINT_JAVAEE_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() ); + putIfNotNull( hints, HINT_JAVAEE_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() ); } final AppliedGraph appliedGraph = getQueryOptions().getAppliedGraph(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmSelectQueryImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmSelectionQueryImpl.java similarity index 73% rename from hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmSelectQueryImpl.java rename to hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmSelectionQueryImpl.java index 4dd460da28..fe446d3e44 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmSelectQueryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmSelectionQueryImpl.java @@ -47,6 +47,7 @@ import org.hibernate.query.spi.SelectQueryPlan; import org.hibernate.query.sqm.SqmSelectionQuery; import org.hibernate.query.sqm.internal.SqmInterpretationsKey.InterpretationsKeySource; import org.hibernate.query.sqm.tree.select.SqmSelectStatement; +import org.hibernate.query.sqm.tree.select.SqmSelection; import jakarta.persistence.FlushModeType; import jakarta.persistence.LockModeType; @@ -68,7 +69,7 @@ import static org.hibernate.query.spi.SqlOmittingQueryOptions.omitSqlQueryOption /** * @author Steve Ebersole */ -public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSelectionQuery, InterpretationsKeySource { +public class SqmSelectionQueryImpl extends AbstractSelectionQuery implements SqmSelectionQuery, InterpretationsKeySource { private final String hql; private final SqmSelectStatement sqm; @@ -76,9 +77,9 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel private final DomainParameterXref domainParameterXref; private final QueryParameterBindingsImpl parameterBindings; - private final Class resultType; + private final Class resultType; - public SqmSelectQueryImpl( + public SqmSelectionQueryImpl( String hql, HqlInterpretation hqlInterpretation, SharedSessionContractImplementor session) { @@ -91,13 +92,23 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel this.parameterBindings = QueryParameterBindingsImpl.from( parameterMetadata, session.getFactory() ); - this.resultType = sqm.getQuerySpec().getSelectClause().getSelections().size() > 1 - ? Object[].class - : Object.class; + this.resultType = determineResultType( sqm ); setComment( hql ); } + private static Class determineResultType(SqmSelectStatement sqm) { + final List> selections = sqm.getQuerySpec().getSelectClause().getSelections(); + if ( selections.size() == 1 ) { + final SqmSelection sqmSelection = selections.get( 0 ); + //noinspection unchecked + return (Class) sqmSelection.getNodeJavaType().getJavaTypeClass(); + } + + //noinspection unchecked + return (Class) Object[].class; + } + @SuppressWarnings("rawtypes") public SqmSelectStatement getSqmStatement() { return sqm; @@ -136,7 +147,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel resetCallback(); } - protected List doList() { + protected List doList() { getSession().prepareForQueryExecution( requiresTxn( getQueryOptions().getLockOptions().findGreatestLockMode() ) ); final SqmSelectStatement sqmStatement = (SqmSelectStatement) getSqmStatement(); @@ -177,7 +188,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel executionContextToUse = this; } - final List list = resolveQueryPlan().performList( executionContextToUse ); + final List list = resolveQueryPlan().performList( executionContextToUse ); if ( needsDistinct ) { int includedCount = -1; @@ -188,9 +199,9 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel final int max = !hasLimit || getQueryOptions().getLimit().getMaxRows() == null ? getMaxRows( sqmStatement, list.size() ) : getQueryOptions().getLimit().getMaxRows(); - final List tmp = new ArrayList<>( list.size() ); + final List tmp = new ArrayList<>( list.size() ); final IdentitySet distinction = new IdentitySet<>( list.size() ); - for ( final Object result : list ) { + for ( final R result : list ) { if ( !distinction.add( result ) ) { continue; } @@ -210,7 +221,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel } @Override - protected ScrollableResultsImplementor doScroll(ScrollMode scrollMode) { + protected ScrollableResultsImplementor doScroll(ScrollMode scrollMode) { getSession().prepareForQueryExecution( requiresTxn( getQueryOptions().getLockOptions().findGreatestLockMode() ) ); return resolveQueryPlan().performScroll( scrollMode, this ); @@ -220,7 +231,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Query plan - private SelectQueryPlan resolveQueryPlan() { + private SelectQueryPlan resolveQueryPlan() { final QueryInterpretationCache.Key cacheKey = SqmInterpretationsKey.createInterpretationsKey( this ); if ( cacheKey != null ) { return getSession().getFactory().getQueryEngine().getInterpretationCache().resolveSelectQueryPlan( @@ -233,7 +244,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel } } - private SelectQueryPlan buildQueryPlan() { + private SelectQueryPlan buildQueryPlan() { final SqmSelectStatement[] concreteSqmStatements = QuerySplitter.split( (SqmSelectStatement) getSqmStatement(), getSession().getFactory() @@ -247,8 +258,9 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel } } - private SelectQueryPlan buildAggregatedQueryPlan(SqmSelectStatement[] concreteSqmStatements) { - final SelectQueryPlan[] aggregatedQueryPlans = new SelectQueryPlan[ concreteSqmStatements.length ]; + private SelectQueryPlan buildAggregatedQueryPlan(SqmSelectStatement[] concreteSqmStatements) { + //noinspection unchecked + final SelectQueryPlan[] aggregatedQueryPlans = new SelectQueryPlan[ concreteSqmStatements.length ]; // todo (6.0) : we want to make sure that certain thing (ResultListTransformer, etc) only get applied at the aggregator-level @@ -260,12 +272,12 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel ); } - return new AggregatedSelectQueryPlanImpl( aggregatedQueryPlans ); + return new AggregatedSelectQueryPlanImpl<>( aggregatedQueryPlans ); } - private SelectQueryPlan buildConcreteQueryPlan( + private SelectQueryPlan buildConcreteQueryPlan( SqmSelectStatement concreteSqmStatement, - Class resultType, + Class resultType, QueryOptions queryOptions) { return new ConcreteSqmSelectQueryPlan<>( concreteSqmStatement, @@ -282,7 +294,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel // InterpretationsKeySource @Override - public Class getResultType() { + public Class getResultType() { return resultType; } @@ -317,7 +329,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel } @Override - public SqmSelectionQuery setFlushMode(FlushModeType flushMode) { + public SqmSelectionQuery setFlushMode(FlushModeType flushMode) { setHibernateFlushMode( FlushModeTypeHelper.getFlushMode( flushMode ) ); return this; } @@ -333,7 +345,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel * @see #setHibernateLockMode */ @Override - public SqmSelectionQuery setLockMode(LockModeType lockMode) { + public SqmSelectionQuery setLockMode(LockModeType lockMode) { setHibernateLockMode( LockModeTypeHelper.getLockMode( lockMode ) ); return this; } @@ -342,7 +354,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel * Specify the root LockMode for the query */ @Override - public SqmSelectionQuery setHibernateLockMode(LockMode lockMode) { + public SqmSelectionQuery setHibernateLockMode(LockMode lockMode) { getLockOptions().setLockMode( lockMode ); return this; } @@ -351,7 +363,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel * Specify a LockMode to apply to a specific alias defined in the query */ @Override - public SqmSelectionQuery setAliasSpecificLockMode(String alias, LockMode lockMode) { + public SqmSelectionQuery setAliasSpecificLockMode(String alias, LockMode lockMode) { getLockOptions().setAliasSpecificLockMode( alias, lockMode ); return this; } @@ -360,7 +372,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel * Specifies whether follow-on locking should be applied? */ @Override - public SqmSelectionQuery setFollowOnLocking(boolean enable) { + public SqmSelectionQuery setFollowOnLocking(boolean enable) { getLockOptions().setFollowOnLocking( enable ); return this; } @@ -371,7 +383,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel } @Override - public SqmSelectionQuery setFetchSize(int fetchSize) { + public SqmSelectionQuery setFetchSize(int fetchSize) { getQueryOptions().setFetchSize( fetchSize ); return this; } @@ -384,7 +396,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel } @Override - public SqmSelectionQuery setReadOnly(boolean readOnly) { + public SqmSelectionQuery setReadOnly(boolean readOnly) { getQueryOptions().setReadOnly( readOnly ); return this; } @@ -394,7 +406,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel } @Override - public SqmSelectionQuery setCacheMode(CacheMode cacheMode) { + public SqmSelectionQuery setCacheMode(CacheMode cacheMode) { getQueryOptions().setCacheMode( cacheMode ); return this; } @@ -405,7 +417,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel } @Override - public SqmSelectionQuery setCacheable(boolean cacheable) { + public SqmSelectionQuery setCacheable(boolean cacheable) { getQueryOptions().setResultCachingEnabled( cacheable ); return this; } @@ -416,7 +428,7 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel } @Override - public SqmSelectionQuery setCacheRegion(String regionName) { + public SqmSelectionQuery setCacheRegion(String regionName) { getQueryOptions().setResultCacheRegionName( regionName ); return this; } @@ -461,242 +473,242 @@ public class SqmSelectQueryImpl extends AbstractSelectionQuery implements SqmSel // covariance @Override - public SqmSelectionQuery setHibernateFlushMode(FlushMode flushMode) { + public SqmSelectionQuery setHibernateFlushMode(FlushMode flushMode) { super.setHibernateFlushMode( flushMode ); return this; } @Override - public SqmSelectionQuery setTimeout(int timeout) { + public SqmSelectionQuery setTimeout(int timeout) { super.setTimeout( timeout ); return this; } @Override - public SqmSelectionQuery setParameter(String name, Object value) { + public SqmSelectionQuery setParameter(String name, Object value) { super.setParameter( name, value ); return this; } @Override - public

SqmSelectionQuery setParameter(String name, P value, Class

javaType) { + public

SqmSelectionQuery setParameter(String name, P value, Class

javaType) { super.setParameter( name, value, javaType ); return this; } @Override - public

SqmSelectionQuery setParameter(String name, P value, BindableType

type) { + public

SqmSelectionQuery setParameter(String name, P value, BindableType

type) { super.setParameter( name, value, type ); return this; } @Override - public SqmSelectionQuery setParameter(String name, Instant value, TemporalType temporalType) { + public SqmSelectionQuery setParameter(String name, Instant value, TemporalType temporalType) { super.setParameter( name, value, temporalType ); return this; } @Override - public SqmSelectionQuery setParameter(int position, Object value) { + public SqmSelectionQuery setParameter(int position, Object value) { super.setParameter( position, value ); return this; } @Override - public

SqmSelectionQuery setParameter(int position, P value, Class

javaType) { + public

SqmSelectionQuery setParameter(int position, P value, Class

javaType) { super.setParameter( position, value, javaType ); return this; } @Override - public

SqmSelectionQuery setParameter(int position, P value, BindableType

type) { + public

SqmSelectionQuery setParameter(int position, P value, BindableType

type) { super.setParameter( position, value, type ); return this; } @Override - public SqmSelectionQuery setParameter(int position, Instant value, TemporalType temporalType) { + public SqmSelectionQuery setParameter(int position, Instant value, TemporalType temporalType) { super.setParameter( position, value, temporalType ); return this; } @Override - public

SqmSelectionQuery setParameter(QueryParameter

parameter, P value) { + public

SqmSelectionQuery setParameter(QueryParameter

parameter, P value) { super.setParameter( parameter, value ); return this; } @Override - public

SqmSelectionQuery setParameter(QueryParameter

parameter, P value, Class

javaType) { + public

SqmSelectionQuery setParameter(QueryParameter

parameter, P value, Class

javaType) { super.setParameter( parameter, value, javaType ); return this; } @Override - public

SqmSelectionQuery setParameter(QueryParameter

parameter, P value, BindableType

type) { + public

SqmSelectionQuery setParameter(QueryParameter

parameter, P value, BindableType

type) { super.setParameter( parameter, value, type ); return this; } @Override - public

SqmSelectionQuery setParameter(Parameter

parameter, P value) { + public

SqmSelectionQuery setParameter(Parameter

parameter, P value) { super.setParameter( parameter, value ); return this; } @Override - public SqmSelectionQuery setParameter(Parameter param, Calendar value, TemporalType temporalType) { + public SqmSelectionQuery setParameter(Parameter param, Calendar value, TemporalType temporalType) { super.setParameter( param, value, temporalType ); return this; } @Override - public SqmSelectionQuery setParameter(Parameter param, Date value, TemporalType temporalType) { + public SqmSelectionQuery setParameter(Parameter param, Date value, TemporalType temporalType) { super.setParameter( param, value, temporalType ); return this; } @Override - public SqmSelectionQuery setParameter(String name, Calendar value, TemporalType temporalType) { + public SqmSelectionQuery setParameter(String name, Calendar value, TemporalType temporalType) { super.setParameter( name, value, temporalType ); return this; } @Override - public SqmSelectionQuery setParameter(String name, Date value, TemporalType temporalType) { + public SqmSelectionQuery setParameter(String name, Date value, TemporalType temporalType) { super.setParameter( name, value, temporalType ); return this; } @Override - public SqmSelectionQuery setParameter(int position, Calendar value, TemporalType temporalType) { + public SqmSelectionQuery setParameter(int position, Calendar value, TemporalType temporalType) { super.setParameter( position, value, temporalType ); return this; } @Override - public SqmSelectionQuery setParameter(int position, Date value, TemporalType temporalType) { + public SqmSelectionQuery setParameter(int position, Date value, TemporalType temporalType) { super.setParameter( position, value, temporalType ); return this; } @Override - public SqmSelectionQuery setParameterList(String name, Collection values) { + public SqmSelectionQuery setParameterList(String name, Collection values) { super.setParameterList( name, values ); return this; } @Override - public

SqmSelectionQuery setParameterList(String name, Collection values, Class

javaType) { + public

SqmSelectionQuery setParameterList(String name, Collection values, Class

javaType) { super.setParameterList( name, values, javaType ); return this; } @Override - public

SqmSelectionQuery setParameterList(String name, Collection values, BindableType

type) { + public

SqmSelectionQuery setParameterList(String name, Collection values, BindableType

type) { super.setParameterList( name, values, type ); return this; } @Override - public SqmSelectionQuery setParameterList(String name, Object[] values) { + public SqmSelectionQuery setParameterList(String name, Object[] values) { super.setParameterList( name, values ); return this; } @Override - public

SqmSelectionQuery setParameterList(String name, P[] values, Class

javaType) { + public

SqmSelectionQuery setParameterList(String name, P[] values, Class

javaType) { super.setParameterList( name, values, javaType ); return this; } @Override - public

SqmSelectionQuery setParameterList(String name, P[] values, BindableType

type) { + public

SqmSelectionQuery setParameterList(String name, P[] values, BindableType

type) { super.setParameterList( name, values, type ); return this; } @Override - public SqmSelectionQuery setParameterList(int position, Collection values) { + public SqmSelectionQuery setParameterList(int position, Collection values) { super.setParameterList( position, values ); return this; } @Override - public

SqmSelectionQuery setParameterList(int position, Collection values, Class

javaType) { + public

SqmSelectionQuery setParameterList(int position, Collection values, Class

javaType) { super.setParameterList( position, values, javaType ); return this; } @Override - public

SqmSelectionQuery setParameterList(int position, Collection values, BindableType

type) { + public

SqmSelectionQuery setParameterList(int position, Collection values, BindableType

type) { super.setParameterList( position, values, type ); return this; } @Override - public SqmSelectionQuery setParameterList(int position, Object[] values) { + public SqmSelectionQuery setParameterList(int position, Object[] values) { super.setParameterList( position, values ); return this; } @Override - public

SqmSelectionQuery setParameterList(int position, P[] values, Class

javaType) { + public

SqmSelectionQuery setParameterList(int position, P[] values, Class

javaType) { super.setParameterList( position, values, javaType ); return this; } @Override - public

SqmSelectionQuery setParameterList(int position, P[] values, BindableType

type) { + public

SqmSelectionQuery setParameterList(int position, P[] values, BindableType

type) { super.setParameterList( position, values, type ); return this; } @Override - public

SqmSelectionQuery setParameterList(QueryParameter

parameter, Collection values) { + public

SqmSelectionQuery setParameterList(QueryParameter

parameter, Collection values) { super.setParameterList( parameter, values ); return this; } @Override - public

SqmSelectionQuery setParameterList(QueryParameter

parameter, Collection values, Class

javaType) { + public

SqmSelectionQuery setParameterList(QueryParameter

parameter, Collection values, Class

javaType) { super.setParameterList( parameter, values, javaType ); return this; } @Override - public

SqmSelectionQuery setParameterList(QueryParameter

parameter, Collection values, BindableType

type) { + public

SqmSelectionQuery setParameterList(QueryParameter

parameter, Collection values, BindableType

type) { super.setParameterList( parameter, values, type ); return this; } @Override - public

SqmSelectionQuery setParameterList(QueryParameter

parameter, P[] values) { + public

SqmSelectionQuery setParameterList(QueryParameter

parameter, P[] values) { super.setParameterList( parameter, values ); return this; } @Override - public

SqmSelectionQuery setParameterList(QueryParameter

parameter, P[] values, Class

javaType) { + public

SqmSelectionQuery setParameterList(QueryParameter

parameter, P[] values, Class

javaType) { super.setParameterList( parameter, values, javaType ); return this; } @Override - public

SqmSelectionQuery setParameterList(QueryParameter

parameter, P[] values, BindableType

type) { + public

SqmSelectionQuery setParameterList(QueryParameter

parameter, P[] values, BindableType

type) { super.setParameterList( parameter, values, type ); return this; } @Override - public SqmSelectionQuery setProperties(Map map) { + public SqmSelectionQuery setProperties(Map map) { super.setProperties( map ); return this; } @Override - public SqmSelectionQuery setProperties(Object bean) { + public SqmSelectionQuery setProperties(Object bean) { super.setProperties( bean ); return this; } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/sqm/untyped/BasicUntypedQueryTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/sqm/untyped/BasicUntypedQueryTests.java index 898e1d747e..93fcf1f08d 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/sqm/untyped/BasicUntypedQueryTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/sqm/untyped/BasicUntypedQueryTests.java @@ -11,6 +11,7 @@ import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.query.SelectionQuery; import org.hibernate.testing.orm.domain.StandardDomainModel; +import org.hibernate.testing.orm.domain.contacts.Contact; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; @@ -23,7 +24,17 @@ import org.junit.jupiter.api.Test; @SessionFactory public class BasicUntypedQueryTests { @Test - public void untypedEntitySelectTest(SessionFactoryScope scope) { + public void typedEntitySelectTest(SessionFactoryScope scope) { + scope.inTransaction( (session) -> { + checkResults( + session.createSelectQuery( "select c from Contact c", Contact.class ), + session + ); + } ); + } + + @Test + public void rawEntitySelectTest(SessionFactoryScope scope) { scope.inTransaction( (session) -> { checkResults( session.createSelectQuery( "select c from Contact c" ), @@ -32,7 +43,31 @@ public class BasicUntypedQueryTests { } ); } - private void checkResults(SelectionQuery query, SessionImplementor session) { + @Test + public void rawScalarSelectTest(SessionFactoryScope scope) { + scope.inTransaction( (session) -> { + checkResults( + session.createSelectQuery( "select c.name from Contact c" ), + session + ); + } ); + } + + @Test + public void typedScalarSelectTest(SessionFactoryScope scope) { + scope.inTransaction( (session) -> { + checkResults( + session.createSelectQuery( "select c.name from Contact c", Contact.Name.class ), + session + ); + checkResults( + session.createSelectQuery( "select c.name.first from Contact c", String.class ), + session + ); + } ); + } + + private void checkResults(SelectionQuery query, SessionImplementor session) { query.list(); query.getResultList(); query.uniqueResult(); @@ -41,14 +76,4 @@ public class BasicUntypedQueryTests { query.scroll( ScrollMode.SCROLL_SENSITIVE ).close(); query.stream().close(); } - - @Test - public void untypedScalarSelectTest(SessionFactoryScope scope) { - scope.inTransaction( (session) -> { - checkResults( - session.createSelectQuery( "select c.name from Contact c" ), - session - ); - } ); - } }