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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:56:41+00:00 2026-06-08T10:56:41+00:00

Given an web app (Java, Spring, Hibernate and Sybase as DB) with several, say

  • 0

Given an web app (Java, Spring, Hibernate and Sybase as DB) with several, say 5 different search screens, I want to count first if the search result based on the user’s criteria will be exceeding a limit, say 1000 rows. Results that are huge, going past 1000 can happen even if user provides reasonable filters and criteria.

Is doing it this way recommended:

  1. select count(*) from table –clauses, etc here
  2. then if > 1000, don’t do actual search, return and show limit error (tell user to refine search)
  3. else if < 1000, do the actual search and give back the resultset to user

Or is there a better solution to handle this?

If this is the way to go, my followup question would be, how can we avoid duplicating the sql query? Because I understand doing this, will require me to declare the same search sql except the select clause will only contain count(*).

UPDATES

Additionally, I want to avoid 2 things:
1. processing from executing the actual sql
2. loading/mapping of the domain objects by the ORM (Hibernate in this case)
* both 1 & 2 are avoided when I detect that the count is > 1000.

  • 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-08T10:56:42+00:00Added an answer on June 8, 2026 at 10:56 am

    I wouldn’t run a COUNT(*) at all, just run the query with a LIMIT 1001. It’s likely you are generating the exact same result set (i.e., to do the COUNT, you have to generate the result set) in the count and the next hit will be from the cache, or at worst you’ll have to recalculate. You’re just doing the same work twice

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

Sidebar

Related Questions

i am new to spring/hibernate and was trying out my first app. I got
Given: a Java EE 5 web app that has a web.xml that has a
I am writing Web app in java using Spring Web MVC framework. Somehow validation
I'm building a jsf Web App in Eclipse, and I've given the app a
Given a web URL, I want to detect all the links in a WEBSITE
We're developing a Java web app that utilizes JSF (Richfaces through Seam) for its
When I'm working on my web app in Eclipse, I can search all the
The top of my web.xml file looks like this: <?xml version=1.0 encoding=UTF-8?> <web-app xmlns=http://java.sun.com/xml/ns/j2ee
I am implementing spring security framework in my web app. I have all the
I have tomcat 7.0.14, jdk1.6 and Eclipse Indigo for Java EE web app developers.

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.