Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7180627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:23:17+00:00 2026-05-28T17:23:17+00:00

Say I have an entity MyEntity , and it has a formula-based property fmlaProp

  • 0

Say I have an entity MyEntity, and it has a formula-based property fmlaProp. Now say I create a criteria:

s.createCriteria(MyEntity.class) 
    .setProjection( 
        Projections.distinct( 
            Projections.property("fmlaProp"))) 
    .addOrder(Order.asc("fmlaProp"));

in this case I get the following SQL:

SELECT DISTINCT fmlaProp-sql FROM MY_ENTITY_TABLE ORDER BY fmlaProp-sql

Which gives an error on Oracle saying that order-by expression is non-selected. Then I tried the following criteria:

s.createCriteria(MyEntity.class) 
    .setProjection( 
        Projections.distinct(
            Projections.alias(
                Projections.property("fmlaProp"),
                "alias1")) 
    .addOrder(Order.asc("alias1"));

Which generates “order by alias1” which works fine. But it is kind of ugly — the code must “know” of those formula properties, which violates “write once” principle. Any thoughts or suggestions on that? Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:23:18+00:00Added an answer on May 28, 2026 at 5:23 pm

    This is expected behavior from Hibernate. It doesn’t have to do with the formula property specifically, but that you want to do ordering with a projected value. From the Hibernate Docs:

    An alias can be assigned to a projection so that the projected value can be referred to in restrictions or orderings. Here are two different ways to do this…

    As far as alternatives, you could try making the formula property a virtual column (in versions of Oracle 11 and above) or wrapping the table in a view with this column computed. That way, Oracle will know fmlaprop directly, which can be used just like a “normal” column.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say we have an entity that has attributes att1 and att2, where att1
Let's say I have this entity (for Hibernate): @Entity public class Person { @Id
Let's say I have the typical entity Car class Car : Entity { public
Hibernate allows you to just say .id. Let's say I have: @Entity public class
Say I have an entity that looks something like this simple example: MyEntity {
Let's say I have the following entity: public class Store { public List<Product> Products
Let's say I have a Meeting entity. Each meeting has a single attendee and
Lets say I have an entity called User which has many Posts. My service
Let's say I have an entity that looks like this: public class Album() {
I have entity fluently mapped to existing oracle view: public class MyEntityMap : ClassMap<MyEntity>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.