diff --git a/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java
index 43041e19f7..e078149fa2 100644
--- a/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java
+++ b/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java
@@ -240,4 +240,8 @@ public interface SharedSessionContract extends QueryProducer, Closeable, Seriali
throw new UnsupportedOperationException();
}
+ /**
+ * The factory which created this session.
+ */
+ SessionFactory getFactory();
}
diff --git a/hibernate-core/src/main/java/org/hibernate/boot/SessionFactoryBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/SessionFactoryBuilder.java
index 09ed7032fa..7a41495cf1 100644
--- a/hibernate-core/src/main/java/org/hibernate/boot/SessionFactoryBuilder.java
+++ b/hibernate-core/src/main/java/org/hibernate/boot/SessionFactoryBuilder.java
@@ -18,7 +18,7 @@ import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
import org.hibernate.jpa.spi.JpaCompliance;
import org.hibernate.loader.BatchFetchStyle;
import org.hibernate.proxy.EntityNotFoundDelegate;
-import org.hibernate.query.sqm.NullPrecedence;
+import org.hibernate.query.NullPrecedence;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector;
diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java
index 53d3fd498c..c377981403 100644
--- a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java
+++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java
@@ -27,7 +27,7 @@ import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
import org.hibernate.internal.SessionFactoryImpl;
import org.hibernate.loader.BatchFetchStyle;
import org.hibernate.proxy.EntityNotFoundDelegate;
-import org.hibernate.query.sqm.NullPrecedence;
+import org.hibernate.query.NullPrecedence;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector;
diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java
index 1db43121db..4d83eb358d 100644
--- a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java
+++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java
@@ -56,7 +56,7 @@ import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode;
import org.hibernate.query.criteria.ValueHandlingMode;
import org.hibernate.query.hql.HqlTranslator;
-import org.hibernate.query.sqm.NullPrecedence;
+import org.hibernate.query.NullPrecedence;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy;
diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryBuilder.java
index 2194d65bb1..74cf408d86 100644
--- a/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryBuilder.java
+++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryBuilder.java
@@ -19,7 +19,7 @@ import org.hibernate.cache.spi.TimestampsCacheFactory;
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
import org.hibernate.loader.BatchFetchStyle;
import org.hibernate.proxy.EntityNotFoundDelegate;
-import org.hibernate.query.sqm.NullPrecedence;
+import org.hibernate.query.NullPrecedence;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector;
diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryOptions.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryOptions.java
index 95ba220c37..eb717bccfa 100644
--- a/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryOptions.java
+++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryOptions.java
@@ -27,7 +27,7 @@ import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode;
import org.hibernate.query.criteria.ValueHandlingMode;
import org.hibernate.query.hql.HqlTranslator;
-import org.hibernate.query.sqm.NullPrecedence;
+import org.hibernate.query.NullPrecedence;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy;
diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/SessionFactoryOptions.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/SessionFactoryOptions.java
index 712c8ac066..f230d9d907 100644
--- a/hibernate-core/src/main/java/org/hibernate/boot/spi/SessionFactoryOptions.java
+++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/SessionFactoryOptions.java
@@ -28,7 +28,7 @@ import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode;
import org.hibernate.query.criteria.ValueHandlingMode;
import org.hibernate.query.spi.QueryEngineOptions;
-import org.hibernate.query.sqm.NullPrecedence;
+import org.hibernate.query.NullPrecedence;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.stat.Statistics;
diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java
index af0370aab5..517cd11748 100644
--- a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java
+++ b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java
@@ -23,7 +23,7 @@ import org.hibernate.id.enhanced.ImplicitDatabaseObjectNamingStrategy;
import org.hibernate.jpa.LegacySpecHints;
import org.hibernate.jpa.SpecHints;
import org.hibernate.query.spi.QueryPlan;
-import org.hibernate.query.sqm.NullPrecedence;
+import org.hibernate.query.NullPrecedence;
import org.hibernate.query.sqm.mutation.internal.temptable.GlobalTemporaryTableStrategy;
import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableStrategy;
import org.hibernate.query.sqm.mutation.internal.temptable.PersistentTableStrategy;
diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionLazyDelegator.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionLazyDelegator.java
index f6a3ffcb48..0df894c9bf 100644
--- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionLazyDelegator.java
+++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionLazyDelegator.java
@@ -57,7 +57,7 @@ import jakarta.persistence.metamodel.Metamodel;
* instance itself is lazily provided via a {@code Supplier}.
* When the decorated instance is readily available, one
* should prefer using {@code SessionDelegatorBaseImpl}.
- *
+ *
* Another difference with SessionDelegatorBaseImpl is that
* this type only implements Session.
*
@@ -67,6 +67,11 @@ public class SessionLazyDelegator implements Session {
private final Supplier lazySession;
+ @Override
+ public SessionFactory getFactory() {
+ return lazySession.get().getFactory();
+ }
+
public SessionLazyDelegator(Supplier lazySessionLookup){
this.lazySession = lazySessionLookup;
}
@@ -505,7 +510,6 @@ public class SessionLazyDelegator implements Session {
return this.lazySession.get().getLobHelper();
}
- @SuppressWarnings("rawtypes")
@Override
public SharedSessionBuilder sessionWithOptions() {
return this.lazySession.get().sessionWithOptions();
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractDomainPath.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractDomainPath.java
index b1494632f9..da36cd32a9 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractDomainPath.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractDomainPath.java
@@ -16,8 +16,8 @@ import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.SelectableMapping;
import org.hibernate.metamodel.mapping.ordering.ast.DomainPath;
import org.hibernate.metamodel.mapping.ordering.ast.OrderingExpression;
-import org.hibernate.query.sqm.NullPrecedence;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.NullPrecedence;
+import org.hibernate.query.SortOrder;
import org.hibernate.sql.ast.spi.SqlAstCreationState;
import org.hibernate.sql.ast.spi.SqlSelection;
import org.hibernate.sql.ast.tree.SqlAstNode;
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/ColumnReference.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/ColumnReference.java
index 3e4bf1b737..6a52d1ffda 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/ColumnReference.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/ColumnReference.java
@@ -12,8 +12,8 @@ import org.hibernate.metamodel.mapping.ModelPartContainer;
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.metamodel.mapping.ordering.TranslationContext;
import org.hibernate.persister.entity.AbstractEntityPersister;
-import org.hibernate.query.sqm.NullPrecedence;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.NullPrecedence;
+import org.hibernate.query.SortOrder;
import org.hibernate.sql.ast.spi.SqlAstCreationState;
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
import org.hibernate.sql.ast.tree.expression.Expression;
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/FunctionExpression.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/FunctionExpression.java
index 3a6f14e94e..ff56416109 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/FunctionExpression.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/FunctionExpression.java
@@ -12,8 +12,8 @@ import java.util.List;
import org.hibernate.metamodel.mapping.CollectionPart;
import org.hibernate.metamodel.mapping.internal.AbstractDomainPath;
-import org.hibernate.query.sqm.NullPrecedence;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.NullPrecedence;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.sqm.function.FunctionRenderingSupport;
import org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression;
import org.hibernate.sql.ast.SqlAstTranslator;
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/OrderingExpression.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/OrderingExpression.java
index bd285c585d..d86eaeaf40 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/OrderingExpression.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/OrderingExpression.java
@@ -6,8 +6,8 @@
*/
package org.hibernate.metamodel.mapping.ordering.ast;
-import org.hibernate.query.sqm.NullPrecedence;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.NullPrecedence;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.sqm.sql.FakeSqmToSqlAstConverter;
import org.hibernate.query.sqm.sql.SqmToSqlAstConverter;
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/OrderingSpecification.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/OrderingSpecification.java
index 71df1f41d3..bfafbe7962 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/OrderingSpecification.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/OrderingSpecification.java
@@ -6,8 +6,8 @@
*/
package org.hibernate.metamodel.mapping.ordering.ast;
-import org.hibernate.query.sqm.NullPrecedence;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.NullPrecedence;
+import org.hibernate.query.SortOrder;
/**
* An individual sort specification in an order-by fragment
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/ParseTreeVisitor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/ParseTreeVisitor.java
index 16e3a414f7..b74bc8086c 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/ParseTreeVisitor.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/ParseTreeVisitor.java
@@ -12,8 +12,8 @@ import java.util.List;
import java.util.Locale;
import org.hibernate.internal.util.QuotingHelper;
-import org.hibernate.query.sqm.NullPrecedence;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.NullPrecedence;
+import org.hibernate.query.SortOrder;
import org.hibernate.grammars.ordering.OrderingParser;
import org.hibernate.grammars.ordering.OrderingParserBaseVisitor;
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/SelfRenderingOrderingExpression.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/SelfRenderingOrderingExpression.java
index 972334aca4..77b2588670 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/SelfRenderingOrderingExpression.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/SelfRenderingOrderingExpression.java
@@ -6,8 +6,8 @@
*/
package org.hibernate.metamodel.mapping.ordering.ast;
-import org.hibernate.query.sqm.NullPrecedence;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.NullPrecedence;
+import org.hibernate.query.SortOrder;
import org.hibernate.sql.ast.spi.SqlAstCreationState;
import org.hibernate.sql.ast.tree.expression.Expression;
import org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression;
diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java
index 6827950b0e..8c7c6bbfe5 100644
--- a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java
+++ b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java
@@ -49,6 +49,7 @@ import org.hibernate.query.BindableType;
import org.hibernate.query.OutputableType;
import org.hibernate.query.Query;
import org.hibernate.query.QueryParameter;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.internal.QueryOptionsImpl;
import org.hibernate.query.procedure.ProcedureParameter;
import org.hibernate.query.results.ResultSetMapping;
@@ -1074,6 +1075,11 @@ public class ProcedureCallImpl
throw new UnsupportedOperationException( "Not supported for procedure calls" );
}
+ @Override
+ public Query sort(SortOrder sortOrder, SingularAttribute super R, ?> attribute) {
+ throw new UnsupportedOperationException( "Not supported for procedure calls" );
+ }
+
@Override
public Query ascending(int element) {
throw new UnsupportedOperationException( "Not supported for procedure calls" );
@@ -1085,7 +1091,7 @@ public class ProcedureCallImpl
}
@Override
- public Query unordered() {
+ public Query clearOrder() {
return this;
}
diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/NullPrecedence.java b/hibernate-core/src/main/java/org/hibernate/query/NullPrecedence.java
similarity index 97%
rename from hibernate-core/src/main/java/org/hibernate/query/sqm/NullPrecedence.java
rename to hibernate-core/src/main/java/org/hibernate/query/NullPrecedence.java
index 6ceb470d8b..3bc3b258fe 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/sqm/NullPrecedence.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/NullPrecedence.java
@@ -4,7 +4,9 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
-package org.hibernate.query.sqm;
+package org.hibernate.query;
+
+import org.hibernate.query.sqm.NullOrdering;
/**
* Defines precedence of null values within {@code ORDER BY} clause.
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 cf18c995d2..4b85b33a31 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/Query.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/Query.java
@@ -905,6 +905,24 @@ public interface Query extends SelectionQuery, MutationQuery, TypedQuery descending(SingularAttribute super R, ?> attribute);
+ @Override
+ Query sort(SortOrder sortOrder, SingularAttribute super R, ?> attribute);
+
+ @Override
+ default Query sort(Sort super R>... sorts) {
+ for (Sort super R> sort: sorts) {
+ SingularAttribute super R,?> attribute = sort.getAttribute();
+ if ( attribute == null ) {
+ attribute =
+ getSession().getFactory().getMetamodel()
+ .entity( sort.getEntityClass() )
+ .getSingularAttribute( sort.getAttributeName() );
+ }
+ sort( sort.getOrder(), attribute );
+ }
+ return this;
+ }
+
@Override
Query ascending(int element);
@@ -912,7 +930,7 @@ public interface Query extends SelectionQuery, MutationQuery, TypedQuery descending(int element);
@Override
- Query unordered();
+ Query clearOrder();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// deprecated methods
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 fe29909370..b37bb8990a 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/SelectionQuery.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/SelectionQuery.java
@@ -493,6 +493,28 @@ public interface SelectionQuery extends CommonQueryContract {
@Incubating
SelectionQuery descending(SingularAttribute super R, ?> attribute);
+ /**
+ * If the result type of this query is an entity class, add an attribute
+ * of the entity to be used to order the query results in the given order.
+ *
+ * @param attribute an attribute of the entity class returned by this query
+ *
+ * @since 6.3
+ */
+ @Incubating
+ SelectionQuery sort(SortOrder sortOrder, SingularAttribute super R, ?> attribute);
+
+ /**
+ * If the result type of this query is an entity class, add one or more
+ * {@linkplain Sort rules} for ordering the query results.
+ *
+ * @param sorts one or more instances of {@link Sort}
+ *
+ * @since 6.3
+ */
+ @Incubating
+ SelectionQuery sort(Sort super R>... sorts);
+
/**
* Add an element of the select list to be used to order the query results
* in ascending order.
@@ -516,7 +538,9 @@ public interface SelectionQuery extends CommonQueryContract {
SelectionQuery descending(int element);
/**
- * Clear the ordering conditions for this query.
+ * Clear the ordering conditions for this query. Discards any ordering
+ * conditions added via {@link #ascending}, {@link #descending}, or
+ * {@link #sort}.
*
* @see #ascending(SingularAttribute)
* @see #descending(SingularAttribute)
@@ -524,7 +548,7 @@ public interface SelectionQuery extends CommonQueryContract {
* @since 6.3
*/
@Incubating
- SelectionQuery unordered();
+ SelectionQuery clearOrder();
/**
* Specify a {@link LockMode} to apply to a specific alias defined in the query
diff --git a/hibernate-core/src/main/java/org/hibernate/query/Sort.java b/hibernate-core/src/main/java/org/hibernate/query/Sort.java
new file mode 100644
index 0000000000..087e7027ee
--- /dev/null
+++ b/hibernate-core/src/main/java/org/hibernate/query/Sort.java
@@ -0,0 +1,94 @@
+package org.hibernate.query;
+
+import jakarta.persistence.metamodel.SingularAttribute;
+
+/**
+ * A rule for sorting an entity type in a query result set.
+ *
+ * This is a convenience class which allows query result ordering
+ * rules to be passed around the system before being applied to
+ * a {@link Query} by calling {@link Query#sort(Sort[])}.
+ *
+ * @param The type of the entity to be sorted
+ *
+ * @see Query#sort(Sort[])
+ *
+ * @author Gavin King
+ *
+ * @since 6.3
+ */
+public class Sort {
+ private final SortOrder order;
+ private final SingularAttribute attribute;
+ private final Class entityClass;
+ private final String attributeName;
+
+ public Sort(SortOrder order, SingularAttribute attribute) {
+ this.order = order;
+ this.attribute = attribute;
+ this.attributeName = attribute.getName();
+ this.entityClass = attribute.getDeclaringType().getJavaType();
+ }
+
+ public Sort(SortOrder order, Class entityClass, String attributeName) {
+ this.order = order;
+ this.entityClass = entityClass;
+ this.attributeName = attributeName;
+ this.attribute = null;
+ }
+
+ public static Sort asc(SingularAttribute attribute) {
+ return new Sort<>(SortOrder.ASCENDING, attribute);
+ }
+
+ public static Sort desc(SingularAttribute attribute) {
+ return new Sort<>(SortOrder.ASCENDING, attribute);
+ }
+
+ public static Sort asc(Class entityClass, String attributeName) {
+ return new Sort<>( SortOrder.ASCENDING, entityClass, attributeName );
+ }
+
+ public static Sort desc(Class entityClass, String attributeName) {
+ return new Sort<>( SortOrder.ASCENDING, entityClass, attributeName );
+ }
+
+ public SortOrder getOrder() {
+ return order;
+ }
+
+ public SingularAttribute getAttribute() {
+ return attribute;
+ }
+
+ public Class getEntityClass() {
+ return entityClass;
+ }
+
+ public String getAttributeName() {
+ return attributeName;
+ }
+
+ @Override
+ public String toString() {
+ return attributeName + " " + order;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if ( o instanceof Sort ) {
+ Sort> that = (Sort>) o;
+ return that.order == order
+ && that.attributeName.equals(attributeName)
+ && that.entityClass.equals(entityClass);
+ }
+ else {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return attributeName.hashCode() + entityClass.hashCode();
+ }
+}
diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/SortOrder.java b/hibernate-core/src/main/java/org/hibernate/query/SortOrder.java
similarity index 88%
rename from hibernate-core/src/main/java/org/hibernate/query/sqm/SortOrder.java
rename to hibernate-core/src/main/java/org/hibernate/query/SortOrder.java
index 6edbfdc23a..0d1b472b3a 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/sqm/SortOrder.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/SortOrder.java
@@ -4,12 +4,16 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
-package org.hibernate.query.sqm;
+package org.hibernate.query;
import java.util.Locale;
/**
+ * Enumerates the directions in which query results may be sorted.
+ *
* @author Steve Ebersole
+ *
+ * @see Sort
*/
public enum SortOrder {
ASCENDING,
diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java
index 907bafdedc..d74f15c0eb 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java
@@ -35,8 +35,8 @@ import jakarta.persistence.criteria.Subquery;
import org.hibernate.Incubating;
import org.hibernate.query.sqm.FrameKind;
-import org.hibernate.query.sqm.NullPrecedence;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.NullPrecedence;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.sqm.TemporalUnit;
import org.hibernate.query.sqm.tree.expression.SqmExpression;
diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaOrder.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaOrder.java
index 7e1d050f9d..a2969d0466 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaOrder.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaOrder.java
@@ -8,8 +8,8 @@ package org.hibernate.query.criteria;
import jakarta.persistence.criteria.Order;
-import org.hibernate.query.sqm.NullPrecedence;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.NullPrecedence;
+import org.hibernate.query.SortOrder;
/**
* @author Steve Ebersole
diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaSearchOrder.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaSearchOrder.java
index 8ba7991888..adb4b635ce 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaSearchOrder.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaSearchOrder.java
@@ -7,10 +7,8 @@
package org.hibernate.query.criteria;
import org.hibernate.Incubating;
-import org.hibernate.query.sqm.NullPrecedence;
-import org.hibernate.query.sqm.SortOrder;
-
-import jakarta.persistence.criteria.Order;
+import org.hibernate.query.NullPrecedence;
+import org.hibernate.query.SortOrder;
/**
* Represents the search order for a recursive CTE (common table expression).
diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/spi/HibernateCriteriaBuilderDelegate.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/spi/HibernateCriteriaBuilderDelegate.java
index f4367df105..b3590fab68 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/criteria/spi/HibernateCriteriaBuilderDelegate.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/spi/HibernateCriteriaBuilderDelegate.java
@@ -51,8 +51,8 @@ import org.hibernate.query.criteria.JpaSimpleCase;
import org.hibernate.query.criteria.JpaSubQuery;
import org.hibernate.query.criteria.JpaWindow;
import org.hibernate.query.criteria.JpaWindowFrame;
-import org.hibernate.query.sqm.NullPrecedence;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.NullPrecedence;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.sqm.TemporalUnit;
import org.hibernate.query.sqm.tree.expression.SqmExpression;
diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java
index 94b18c5f6d..2f9525073c 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java
@@ -79,10 +79,10 @@ import org.hibernate.query.sqm.FrameKind;
import org.hibernate.query.sqm.FrameMode;
import org.hibernate.query.sqm.LiteralNumberFormatException;
import org.hibernate.query.sqm.NodeBuilder;
-import org.hibernate.query.sqm.NullPrecedence;
+import org.hibernate.query.NullPrecedence;
import org.hibernate.query.sqm.ParsingException;
import org.hibernate.query.sqm.SetOperator;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.sqm.SqmExpressible;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.SqmQuerySource;
diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/spi/SqmQueryImplementor.java b/hibernate-core/src/main/java/org/hibernate/query/hql/spi/SqmQueryImplementor.java
index 038972830a..ef26b39870 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/hql/spi/SqmQueryImplementor.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/hql/spi/SqmQueryImplementor.java
@@ -22,13 +22,14 @@ import org.hibernate.graph.RootGraph;
import org.hibernate.query.BindableType;
import org.hibernate.query.QueryParameter;
import org.hibernate.query.ResultListTransformer;
+import org.hibernate.query.SelectionQuery;
import org.hibernate.query.TupleTransformer;
import org.hibernate.query.named.NameableQuery;
import org.hibernate.query.named.NamedQueryMemento;
import org.hibernate.query.spi.ParameterMetadataImplementor;
import org.hibernate.query.spi.QueryImplementor;
import org.hibernate.query.spi.SqmQuery;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.sqm.tree.SqmStatement;
import org.hibernate.transform.ResultTransformer;
@@ -136,6 +137,12 @@ public interface SqmQueryImplementor extends QueryImplementor, SqmQuery, N
return this;
}
+ @Override
+ default SqmQueryImplementor sort(SortOrder sortOrder, SingularAttribute super R, ?> attribute) {
+ addOrdering( attribute, sortOrder );
+ return this;
+ }
+
@Override
default SqmQueryImplementor ascending(int element) {
addOrdering( element, SortOrder.ASCENDING );
@@ -153,7 +160,7 @@ public interface SqmQueryImplementor extends QueryImplementor, SqmQuery, N
SqmQueryImplementor addOrdering(int element, SortOrder order);
@Override
- SqmQueryImplementor unordered();
+ SqmQueryImplementor clearOrder();
@Override
SqmQueryImplementor setParameter(String name, Object value);
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 e82d96d660..5a336aae9c 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
@@ -39,6 +39,7 @@ import org.hibernate.query.IllegalQueryOperationException;
import org.hibernate.query.Query;
import org.hibernate.query.QueryParameter;
import org.hibernate.query.ResultListTransformer;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.TupleTransformer;
import org.hibernate.query.named.NamedQueryMemento;
@@ -287,6 +288,11 @@ public abstract class AbstractQuery
throw new UnsupportedOperationException( "Should be implemented by " + this.getClass().getName() );
}
+ @Override
+ public Query sort(SortOrder sortOrder, SingularAttribute super R, ?> attribute) {
+ throw new UnsupportedOperationException( "Should be implemented by " + this.getClass().getName() );
+ }
+
@Override
public Query ascending(int element) {
throw new UnsupportedOperationException( "Should be implemented by " + this.getClass().getName() );
@@ -298,7 +304,7 @@ public abstract class AbstractQuery
}
@Override
- public Query unordered() {
+ public Query clearOrder() {
throw new UnsupportedOperationException( "Should be implemented by " + this.getClass().getName() );
}
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 b6bb45e1c9..4841db6aaf 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
@@ -48,6 +48,7 @@ import org.hibernate.query.PathException;
import org.hibernate.query.Query;
import org.hibernate.query.QueryParameter;
import org.hibernate.query.ResultListTransformer;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.TupleTransformer;
import org.hibernate.query.internal.ParameterMetadataImpl;
import org.hibernate.query.internal.QueryOptionsImpl;
@@ -1510,6 +1511,11 @@ public class NativeQueryImpl
throw new UnsupportedOperationException("Not yet supported for native queries");
}
+ @Override
+ public Query sort(SortOrder sortOrder, SingularAttribute super R, ?> attribute) {
+ throw new UnsupportedOperationException("Not yet supported for native queries");
+ }
+
@Override
public Query ascending(int element) {
throw new UnsupportedOperationException("Not yet supported for native queries");
@@ -1521,7 +1527,7 @@ public class NativeQueryImpl
}
@Override
- public Query unordered() {
+ public Query clearOrder() {
return this;
}
diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java
index 34e943fb88..bf8efbac11 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java
@@ -19,6 +19,8 @@ import java.util.Set;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.model.domain.JpaMetamodel;
+import org.hibernate.query.NullPrecedence;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
import org.hibernate.query.criteria.JpaCoalesce;
import org.hibernate.query.criteria.JpaCompoundSelection;
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 c5ea47f1dc..03ad95c7d4 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
@@ -78,7 +78,7 @@ import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.query.spi.ScrollableResultsImplementor;
import org.hibernate.query.spi.SelectQueryPlan;
import org.hibernate.query.sqm.NodeBuilder;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.internal.SqmInterpretationsKey.InterpretationsKeySource;
import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
@@ -1004,7 +1004,7 @@ public class QuerySqmImpl
}
@Override
- public SqmQueryImplementor unordered() {
+ public SqmQueryImplementor clearOrder() {
if ( sqm instanceof SqmSelectStatement ) {
sqm = sqm.copy( SqmCopyContext.noParamCopyContext() );
SqmSelectStatement select = (SqmSelectStatement) sqm;
diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java
index caedf16dc8..4f8aef9f88 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java
@@ -69,9 +69,9 @@ import org.hibernate.query.sqm.BinaryArithmeticOperator;
import org.hibernate.query.sqm.ComparisonOperator;
import org.hibernate.query.sqm.FrameKind;
import org.hibernate.query.sqm.NodeBuilder;
-import org.hibernate.query.sqm.NullPrecedence;
+import org.hibernate.query.NullPrecedence;
import org.hibernate.query.sqm.SetOperator;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.sqm.SqmExpressible;
import org.hibernate.query.sqm.SqmQuerySource;
import org.hibernate.query.sqm.TemporalUnit;
diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmSelectionQueryImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmSelectionQueryImpl.java
index 44e6b77afa..6dcb748076 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmSelectionQueryImpl.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmSelectionQueryImpl.java
@@ -35,8 +35,11 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.graph.spi.AppliedGraph;
import org.hibernate.internal.util.collections.IdentitySet;
import org.hibernate.query.BindableType;
+import org.hibernate.query.Query;
import org.hibernate.query.QueryLogging;
import org.hibernate.query.QueryParameter;
+import org.hibernate.query.SelectionQuery;
+import org.hibernate.query.Sort;
import org.hibernate.query.criteria.internal.NamedCriteriaQueryMementoImpl;
import org.hibernate.query.hql.internal.NamedHqlQueryMementoImpl;
import org.hibernate.query.hql.internal.QuerySplitter;
@@ -55,7 +58,7 @@ import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.query.spi.ScrollableResultsImplementor;
import org.hibernate.query.spi.SelectQueryPlan;
import org.hibernate.query.sqm.NodeBuilder;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.sqm.SqmSelectionQuery;
import org.hibernate.query.sqm.internal.SqmInterpretationsKey.InterpretationsKeySource;
import org.hibernate.query.sqm.tree.SqmCopyContext;
@@ -569,6 +572,27 @@ public class SqmSelectionQueryImpl extends AbstractSelectionQuery
return this;
}
+ @Override
+ public SelectionQuery sort(SortOrder sortOrder, SingularAttribute super R, ?> attribute) {
+ addOrdering( attribute, sortOrder );
+ return null;
+ }
+
+ @Override @SafeVarargs
+ public final SqmSelectionQuery sort(Sort super R>... sorts) {
+ for (Sort super R> sort: sorts) {
+ SingularAttribute super R,?> attribute = sort.getAttribute();
+ if ( attribute == null ) {
+ attribute =
+ getSession().getFactory().getMetamodel()
+ .entity( sort.getEntityClass() )
+ .getSingularAttribute( sort.getAttributeName() );
+ }
+ sort( sort.getOrder(), attribute );
+ }
+ return this;
+ }
+
@Override
public SqmSelectionQuery ascending(int element) {
addOrdering( element, SortOrder.ASCENDING );
@@ -618,7 +642,7 @@ public class SqmSelectionQueryImpl extends AbstractSelectionQuery
}
@Override
- public SqmSelectionQuery unordered() {
+ public SqmSelectionQuery clearOrder() {
sqm = sqm.copy( SqmCopyContext.noParamCopyContext() );
sqm.getQueryPart().setOrderByClause( null );
return this;
diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmInsertStrategyHelper.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmInsertStrategyHelper.java
index bc8a0989b6..cb5fd24533 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmInsertStrategyHelper.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/SqmInsertStrategyHelper.java
@@ -11,7 +11,7 @@ import java.util.Collections;
import java.util.List;
import org.hibernate.engine.spi.SessionFactoryImplementor;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.sqm.function.SelfRenderingWindowFunctionSqlAstExpression;
import org.hibernate.sql.ast.spi.SqlSelection;
import org.hibernate.sql.ast.tree.expression.Expression;
diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertHandler.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertHandler.java
index 3a3ac4b9ac..9b77da839f 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertHandler.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/cte/CteInsertHandler.java
@@ -38,7 +38,7 @@ import org.hibernate.query.results.TableGroupImpl;
import org.hibernate.query.spi.DomainQueryExecutionContext;
import org.hibernate.query.sqm.BinaryArithmeticOperator;
import org.hibernate.query.sqm.ComparisonOperator;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.sqm.internal.DomainParameterXref;
import org.hibernate.query.sqm.internal.SqmJdbcExecutionContextAdapter;
import org.hibernate.query.sqm.internal.SqmUtil;
diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/InsertExecutionDelegate.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/InsertExecutionDelegate.java
index d24ad452f2..af4e915897 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/InsertExecutionDelegate.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/InsertExecutionDelegate.java
@@ -41,7 +41,7 @@ import org.hibernate.query.SemanticException;
import org.hibernate.query.results.TableGroupImpl;
import org.hibernate.query.spi.DomainQueryExecutionContext;
import org.hibernate.query.sqm.ComparisonOperator;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.sqm.internal.DomainParameterXref;
import org.hibernate.query.sqm.internal.SqmUtil;
import org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter;
diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java
index d10777de00..a8ba2593c9 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java
@@ -134,7 +134,7 @@ import org.hibernate.query.sqm.ComparisonOperator;
import org.hibernate.query.sqm.DynamicInstantiationNature;
import org.hibernate.query.sqm.FetchClauseType;
import org.hibernate.query.sqm.InterpretationException;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.sqm.SqmExpressible;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.SqmQuerySource;
diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/cte/SqmCteStatement.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/cte/SqmCteStatement.java
index ae7f27ac1f..f0ba434f86 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/cte/SqmCteStatement.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/cte/SqmCteStatement.java
@@ -15,8 +15,7 @@ import org.hibernate.query.criteria.JpaCteCriteria;
import org.hibernate.query.criteria.JpaCteCriteriaAttribute;
import org.hibernate.query.criteria.JpaCteCriteriaType;
import org.hibernate.query.criteria.JpaSearchOrder;
-import org.hibernate.query.sqm.NullPrecedence;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.sqm.tree.expression.SqmExpression;
import org.hibernate.query.sqm.tree.expression.SqmLiteral;
import org.hibernate.query.sqm.tree.select.SqmSelectQuery;
@@ -28,11 +27,9 @@ import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.tree.AbstractSqmNode;
import org.hibernate.query.sqm.tree.SqmCopyContext;
-import org.hibernate.query.sqm.tree.SqmStatement;
import org.hibernate.query.sqm.tree.SqmVisitableNode;
import jakarta.persistence.criteria.AbstractQuery;
-import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Subquery;
/**
diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/cte/SqmSearchClauseSpecification.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/cte/SqmSearchClauseSpecification.java
index 71d6e4e578..28db68c95b 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/cte/SqmSearchClauseSpecification.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/cte/SqmSearchClauseSpecification.java
@@ -8,8 +8,8 @@ package org.hibernate.query.sqm.tree.cte;
import org.hibernate.query.criteria.JpaCteCriteriaAttribute;
import org.hibernate.query.criteria.JpaSearchOrder;
-import org.hibernate.query.sqm.NullPrecedence;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.NullPrecedence;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.sqm.tree.SqmCopyContext;
/**
diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSortSpecification.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSortSpecification.java
index 841d0d82f8..d149f4eb61 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSortSpecification.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSortSpecification.java
@@ -6,8 +6,8 @@
*/
package org.hibernate.query.sqm.tree.select;
-import org.hibernate.query.sqm.NullPrecedence;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.NullPrecedence;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.criteria.JpaExpression;
import org.hibernate.query.criteria.JpaOrder;
import org.hibernate.query.sqm.tree.SqmCopyContext;
diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java
index 9d2cd405b0..bd18dae594 100644
--- a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java
+++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java
@@ -69,9 +69,9 @@ import org.hibernate.query.sqm.FetchClauseType;
import org.hibernate.query.sqm.FrameExclusion;
import org.hibernate.query.sqm.FrameKind;
import org.hibernate.query.sqm.FrameMode;
-import org.hibernate.query.sqm.NullPrecedence;
+import org.hibernate.query.NullPrecedence;
import org.hibernate.query.sqm.SetOperator;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.SortOrder;
import org.hibernate.query.sqm.UnaryArithmeticOperator;
import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor;
import org.hibernate.query.sqm.function.MultipatternSqmFunctionDescriptor;
diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/SearchClauseSpecification.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/SearchClauseSpecification.java
index 62af26d8a5..0358f1299c 100644
--- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/SearchClauseSpecification.java
+++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/cte/SearchClauseSpecification.java
@@ -6,8 +6,8 @@
*/
package org.hibernate.sql.ast.tree.cte;
-import org.hibernate.query.sqm.NullPrecedence;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.NullPrecedence;
+import org.hibernate.query.SortOrder;
/**
* @author Christian Beikov
diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/SortSpecification.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/SortSpecification.java
index cabd16543f..626a16820c 100644
--- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/SortSpecification.java
+++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/SortSpecification.java
@@ -6,8 +6,8 @@
*/
package org.hibernate.sql.ast.tree.select;
-import org.hibernate.query.sqm.NullPrecedence;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.NullPrecedence;
+import org.hibernate.query.SortOrder;
import org.hibernate.sql.ast.SqlAstWalker;
import org.hibernate.sql.ast.tree.SqlAstNode;
import org.hibernate.sql.ast.tree.expression.Expression;
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/collectionelement/ordered/ElementCollectionSortingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/collectionelement/ordered/ElementCollectionSortingTest.java
index be1b95cdde..49fc966d63 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/collectionelement/ordered/ElementCollectionSortingTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/collectionelement/ordered/ElementCollectionSortingTest.java
@@ -12,7 +12,7 @@ import java.util.List;
import org.hibernate.Session;
import org.hibernate.engine.spi.SessionImplementor;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.SortOrder;
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.metamodel.mapping.ordering.OrderByFragmentImpl;
import org.hibernate.metamodel.mapping.ordering.ast.OrderingSpecification;
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/CriteriaOrderedSetAggregateTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/CriteriaOrderedSetAggregateTest.java
index a0ab45518b..6126f4eaa2 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/CriteriaOrderedSetAggregateTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/CriteriaOrderedSetAggregateTest.java
@@ -19,8 +19,8 @@ import org.hibernate.query.criteria.JpaCrossJoin;
import org.hibernate.query.criteria.JpaExpression;
import org.hibernate.query.criteria.JpaRoot;
import org.hibernate.query.criteria.JpaWindow;
-import org.hibernate.query.sqm.NullPrecedence;
-import org.hibernate.query.sqm.SortOrder;
+import org.hibernate.query.NullPrecedence;
+import org.hibernate.query.SortOrder;
import org.hibernate.testing.orm.domain.StandardDomainModel;
import org.hibernate.testing.orm.domain.gambit.EntityOfBasics;
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/order/OrderTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/order/OrderTest.java
index bd90948a28..477c03c0c7 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/order/OrderTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/order/OrderTest.java
@@ -68,7 +68,7 @@ public class OrderTest {
assertEquals("Hibernate in Action", titlesAsc.get(1));
assertEquals("Java Persistence with Hibernate", titlesAsc.get(0));
titlesAsc = session.createSelectionQuery("from Book order by isbn asc", Book.class)
- .unordered()
+ .clearOrder()
.ascending(title)
.getResultList()
.stream().map(book -> book.title)
@@ -134,7 +134,7 @@ public class OrderTest {
assertEquals("Java Persistence with Hibernate", titlesAsc.get(0));
titlesAsc = session.createSelectionQuery("from Book where title like ?1 order by isbn asc", Book.class)
.setParameter(1, "%Hibernate%")
- .unordered()
+ .clearOrder()
.ascending(title)
.getResultList()
.stream().map(book -> book.title)
@@ -200,7 +200,7 @@ public class OrderTest {
assertEquals("Java Persistence with Hibernate", titlesAsc.get(0));
titlesAsc = session.createSelectionQuery("from Book where title like :title order by isbn asc", Book.class)
.setParameter("title", "%Hibernate%")
- .unordered()
+ .clearOrder()
.ascending(title)
.getResultList()
.stream().map(book -> book.title)
diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/sqm/SortSpecificationReversalTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/sqm/SortSpecificationReversalTests.java
index e5a8045d99..ebbf5777db 100644
--- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/sqm/SortSpecificationReversalTests.java
+++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/sqm/SortSpecificationReversalTests.java
@@ -13,9 +13,9 @@ import org.hibernate.query.sqm.tree.select.SqmSortSpecification;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
-import static org.hibernate.query.sqm.NullPrecedence.FIRST;
-import static org.hibernate.query.sqm.SortOrder.ASCENDING;
-import static org.hibernate.query.sqm.SortOrder.DESCENDING;
+import static org.hibernate.query.NullPrecedence.FIRST;
+import static org.hibernate.query.SortOrder.ASCENDING;
+import static org.hibernate.query.SortOrder.DESCENDING;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.mockito.Mockito.mock;