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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:03:56+00:00 2026-05-25T06:03:56+00:00

My application uses Hibernate to connect to SQL Server. I recently changed my DAO

  • 0

My application uses Hibernate to connect to SQL Server. I recently changed my DAO function that retrieves the count from one of the tables from “return query.getResultList().get(0)” to “query.getSingleResult()”. The sql count() query is supplied via namedQuery.

When I made this change, I noticed that the SQL generated by Hibernate has now changed from
select count(test0_.TestId) as …..
to
select top 2 count(test0_.TestId) as…

Why would Hibernate translate to top 2 and not top 1 for getSingleResult()?
Is there a way to turn off Hibernate modifying my count() query to use top 2 ?

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-25T06:03:57+00:00Added an answer on May 25, 2026 at 6:03 am

    getSingleResult throws an exception if there is not exactly one result. This is so it can check if there are more than one rows returned.

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

Sidebar

Related Questions

Our application uses Hibernate with Sql Server 2005. Being a DBA, I am not
I have an application that uses Hibernate for its domain objects. One part of
I have a client application that connects to a server. The server uses hibernate
I have a JPA/Spring application that uses Hibernate as the JPA provider. In one
We have an application that uses NHibernate to connect to our database on SQL
I have an application that uses Hibernate to connect to my MySQL database. I'm
I have an application that uses hibernate. At one part I am trying to
We have an application that uses Hibernate's 2nd level caching to avoid database hits.
I've deployed an Apache Wicket web-application that uses Spring and Hibernate to my Tomcat
I have an application that uses hibernate and JPA to handle the database. 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.