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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:28:36+00:00 2026-06-17T17:28:36+00:00

I have a hql query like this: return (long)Session.CreateQuery ( select count(*) + from

  • 0

I have a hql query like this:

  return (long)Session.CreateQuery (" select count(*) " +
                                      "   from Files p " +
                                      "   join fetch p.Application a " +
                                      "  where a.Name = :AppName")
                        .SetParameter("AppName", application)                            
                        .UniqueResult();

Hibernate creates sql query like this:

   select field1, field2, field3, count(*)

That’s why it cannot be executed.

Why select count(*) makes hibernate to list all fields and how to prevent it?

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-06-17T17:28:38+00:00Added an answer on June 17, 2026 at 5:28 pm

    In my opinion, the problem comes with the use of ‘FETCH‘, which is normally used to get the dependencies of a given entity from the database. So Hibernate queries the fields of Application to create the objects.

    If you only want to count the files associated to an application, change ‘JOIN FETCH‘ for ‘INNER JOIN‘ (or simply ‘JOIN‘). The only queried field should be count(*) then.

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

Sidebar

Related Questions

I have HQL like this: from Table1 t1 where t1.name not in (select t2.name
With this HQL query: SELECT DISTINCT fs FROM FileStatus fs WHERE UPPER(STR(fs.filePath)) LIKE :FILE_PATH
I have written a code like this to fetch data from database using HQL:
I have a following HQL query: SELECT s.id FROM stack s WHERE s.category is
I need to return a constant from an HQL query in NHIbernate SELECT new
I am having a trouble with executing an HQL query like this: select new
We are using grails-groovy with Hibernate, I have a SQL query like this in
I have a query created with Hibernate Criteria like this: Criteria criteria = db.getSession().createCriteria(Vendor.class);
Currently I have the following code: switch (publicationType) { case PublicationType.Book: return Session.Query<Publication>() .Where(p
I have an hibernate HQL (oracle 10g) thats like this update table1 set modified_timestamp=systimestamp

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.