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

  • Home
  • SEARCH
  • 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 807751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:27:07+00:00 2026-05-15T00:27:07+00:00

Do Hibernate Projection aliases even work? I could swear it just doesn’t. At least,

  • 0

Do Hibernate Projection aliases even work? I could swear it just doesn’t. At least, it doesn’t do what I would expect it to do.

Here is the java:

return sessionFactory.getCurrentSession()
    .createCriteria(PersonProgramActivity.class)
    .setProjection(Projections.projectionList()
        .add(Projections.alias(Projections.sum("numberOfPoints"), "number_of_points"))
        .add(Projections.groupProperty("person.id")))
    .setFirstResult(start)
    .setFetchSize(size)
    .addOrder(Order.desc("numberOfPoints"))
    .list();

Here is the SQL that it generates:

select
    sum(this_.number_of_points) as y0_,
    this_.person_id as y1_
from
    PERSON_PROGRAM_ACTIVITY this_
group by
    this_.person_id
order by
    this_.number_of_points desc

It doesn’t seem to use the alias at all. I would think setting the alias would mean that sum(this_.number_of_points) would be aliased as number_of_points and not y0_. Is there some trick I am missing?

Thanks.

  • 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-15T00:27:08+00:00Added an answer on May 15, 2026 at 12:27 am

    You need to give the entire criteria an alias, then you can create other aliases that actually get used. What is strange is that the aliases get turned into y0_ instead of the other way around.

    return sessionFactory.getCurrentSession()
        .createCriteria(PersonProgramActivity.class, "ppa")
        .setProjection(Projections.projectionList()
            .add(Projections.alias(Projections.sum("numberOfPoints"), "ppa.numberOfPoints"))
            .add(Projections.groupProperty("person.id")))
        .setFirstResult(start)
        .setFetchSize(size)
        .addOrder(Order.desc("ppa.numberOfPoints"))
        .list();
    

    Generates the following SQL:

    select
        sum(this_.number_of_points) as y0_,
        this_.person_id as y1_
    from
        PERSON_PROGRAM_ACTIVITY this_
    group by
        this_.person_id
    order by
        this_.y0_ desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To make it short: hibernate doesn't support projections and query by example? I found
I am using Hibernate in a Java application to access my Database and it
I'm using Hibernate for ORM of my Java app to an Oracle database (not
Hibernate has a handful of methods that, one way or another, takes your object
With Hibernate, can you create a composite ID where one of the columns you
Does hibernate HQL queries support using select min, max, count and other sql functions?
My understanding of Hibernate is that as objects are loaded from the DB they
I am currently using Hibernate Tools 3.1; I customized naming convention and DAO templates.
Can I configure hibernate properties to connect without using an instance name to sql
I have one hibernate sequence, that generates all sequence-numbers in my app. When I

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.