# @Formula with Sort

**URL:** <https://discourse.hibernate.org/t/formula-with-sort/5320>\
**Category:** Hibernate ORM\
**Created:** [May 3, 2021, 8:08am UTC](https://discourse.hibernate.org/t/formula-with-sort/5320 "2021-05-03T08:08:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cobby](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@cobby](https://discourse.hibernate.org/u/cobby)\
**Post date:** [May 3, 2021, 8:08am UTC](https://discourse.hibernate.org/t/formula-with-sort/5320/1 "2021-05-03T08:08:28Z")

</div>

## I have tow fields for 1st name and last name, I use formula to concat them. Im using Pageable to sort the results, but I cant sort with the Formula field. Observation

- When no colum name is specified the the concat is named as formula1
- when name is specified as ‘as’ in query fragment the name of concat is also formula1
- when colum name is specified the name in query is created as a combination of entity class name  
and field name in camal case

when I use the generated name it throws PropertyReferenceException  
does anyone know how to handle this situation properly

---

<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:** [May 3, 2021, 8:27am UTC](https://discourse.hibernate.org/t/formula-with-sort/5320/2 "2021-05-03T08:27:35Z")

</div>

Please share your model, repository, usage and the generated SQL with us, otherwise it’s hard to understand what is going on. Spring Data usually works on the domain/entity level, so whatever you name the property/field in your entity that uses `@Formula`, you will have to use that name for the `Sort`.

---

<div class="post-metadata">

**Author:** ![cobby](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@cobby](https://discourse.hibernate.org/u/cobby)\
**Post date:** [May 3, 2021, 8:50am UTC](https://discourse.hibernate.org/t/formula-with-sort/5320/3 "2021-05-03T08:50:12Z")

</div>

Thanks for the replay. I looked into the issue more and figured it out, its was a mistake on my side.

---

<div class="post-metadata">

**Author:** ![cobby](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@cobby](https://discourse.hibernate.org/u/cobby)\
**Post date:** [May 3, 2021, 8:51am UTC](https://discourse.hibernate.org/t/formula-with-sort/5320/4 "2021-05-03T08:51:32Z")

</div>

if I dont specify colum name it will be mapped to the field name, and i can use the field name for sorting
