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 7990077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:54:26+00:00 2026-06-04T12:54:26+00:00

I want to write following sql using projection in hibernate SELECT id, name, MAX(ver)

  • 0

I want to write following sql using projection in hibernate

SELECT id, name, MAX(ver)
  FROM bizterm
 WHERE name ILIKE '%AB%'
 GROUP BY name, id  order by name asc

I have written following code

Session session=sessionFactory.getCurrentSession();
            Criteria criteria=session.createCriteria(BizTerm.class);
            criteria.add(Restrictions.ilike("name", searchString,MatchMode.ANYWHERE));
            criteria.addOrder(Order.asc("name"));
            ProjectionList projList=Projections.projectionList();
            projList.add(Projections.max("ver"));
            projList.add(Projections.groupProperty("id"));
            projList.add(Projections.groupProperty("name"));
            criteria.setProjection(projList);

In the table id,ver are the PKEY.
This query is running fine but in result I am getting value of only 3 column that is ver,id,name that too as Object,There are other column like status,level in the BizTerm table those value are not getting returned in the result set. How can I get those using projection? I tried projList.add(Projections.property("status")); but its not working.
I want this query to be executed

SELECT id, name,status,level MAX(ver)
  FROM bizterm
 WHERE name ILIKE '%AB%'
 GROUP BY name, id  order by name asc using projection in hibernate
  • 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-06-04T12:54:27+00:00Added an answer on June 4, 2026 at 12:54 pm

    Did like this..now its working no error

    Criteria criteria=session.createCriteria(BizTerm.class);
                criteria.add(Restrictions.ilike("bizTermName", searchString,MatchMode.ANYWHERE));
                criteria.addOrder(Order.asc("bizTermName"));
                ProjectionList projList=Projections.projectionList();
                projList.add(Projections.max("bizTermversion"));
                projList.add(Projections.groupProperty("bizTermId"));
                projList.add(Projections.groupProperty("bizTermName"));
                projList.add(Projections.max("status"));
                projList.add(Projections.max("levels"));
                projList.add(Projections.max("createDate"));
                projList.add(Projections.max("modifyDate"));
    

    Note: I dont need maximum of status,levels,createDate,modifyDate but if I am not writing them inside max function then getting following error

    [Error Code: 0, SQL State: 42803]  : column "levels" must appear in the GROUP BY clause or be used in an aggregate function
    

    with max function everything seems to be fine

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

Sidebar

Related Questions

I want to write the following (pseudo) SQL statement in MS Access: Select C
I want to write a SQL query like the following. Its syntax is not
I want to write a .xml file using the following code into the App_Data/posts.
I am using RIA services with Entity Framework- I have the following sql select
I want to reproduce the following query using criteria: select a.ID as article, count(c.ID)
I want to write the following procedure / function: procedure ShowSysPopup(aFile: string; x, y:
I want to write the following C# code equivalent in JavaScript/jQuery (x == 0
I want to write my xml with following format. How can i do it?I
I wrote the following regex in perl and now i want to write it
I want to create URL re-write rules for following URL in htaccess. http://example.com/vedios/category/fun/ ->

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.