# About SQL sort clause generation

**URL:** <https://discourse.hibernate.org/t/about-sql-sort-clause-generation/11100>\
**Category:** Hibernate ORM\
**Created:** [February 21, 2025, 3:00am UTC](https://discourse.hibernate.org/t/about-sql-sort-clause-generation/11100 "2025-02-21T03:00:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jayden](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@Jayden](https://discourse.hibernate.org/u/Jayden)\
**Post date:** [February 21, 2025, 3:00am UTC](https://discourse.hibernate.org/t/about-sql-sort-clause-generation/11100/1 "2025-02-21T03:00:14Z")

</div>

```auto
CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
Root<Entity> from = cq.from(Entity.class);
cq.multiselect(from.get(Entity_.field1),from.get(Entity_.field2))
       .where(
               ... predicates
        )
        .orderBy(cb.asc(from.get(Entity_.field1)));

```

When using `Object[].class` to create a `CriteriaQuery` with `multiselect` (without specifying aliases), the generated SQL `ORDER BY` clause appears as `ORDER BY 1` (positional index) instead of the column name (e.g., `id` ).  
Is there any configuration or alternative approach to force Hibernate to always generate `ORDER BY` clauses using column names (e.g., `ORDER BY id` ) rather than positional indexes?  
THANKS

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [February 24, 2025, 5:09pm UTC](https://discourse.hibernate.org/t/about-sql-sort-clause-generation/11100/2 "2025-02-24T17:09:52Z")

</div>

There is no such configuration. This is a standard SQL feature and Hibernate ORM makes use of it to reduce the size of the SQL and improve readability. If one of your select items were an expression that contains a query parameter, using the alias/ordinal reference would also be the only way to make this work properly.
