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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:56:08+00:00 2026-05-24T17:56:08+00:00

I am trying to implement paging in hibernate and i am seeing some weird

  • 0

I am trying to implement paging in hibernate and i am seeing some weird behavior from hibernate. I have tried two queries with the same result

List<SomeData> dataList = (List<SomeData>) session.getCurrentSession()
    .createQuery("from SomeData ad where ad.bar = :bar order    by ad.id.name")
    .setString("bar", foo)
    .setFirstResult(i*PAGE_SIZE)
    .setMaxResults(PAGE_SIZE)
    .setFetchSize(PAGE_SIZE) // page_size is 1000 in my case
    .list();

and

List<SomeData> datalist= (List<SomeData>) session.getCurrentSession()
    .createCriteria(SomeData.class)
    .addOrder(Order.asc("id.name"))
    .add(Expression.eq("bar", foo))
    .setFirstResult(i*PAGE_SIZE)
    .setMaxResults(PAGE_SIZE)
    .list();

I have this in a for loop and each time this query runs, the run time increases. The first call returns in 100 ms, the second in 150 and the 5th call takes 2 seconds and so on.

Looking in the server (MySql 5.1.36) logs, I see that the select query does get generated properly with the LIMIT clause but for each record that is returned, hibernate for some reason also emits an update query. after the first result, it updates 1000 records, after the second result, it updates 2000 records and so on. So for a page size of 1000 and 5 iterations of the loop, the database is getting hit with 15,000 queries (5K + 4K + 3K + 2K + 1K ) Why is that happening?

I tried making a native SQL query and it worked as expected. The query is

List asins = (List) session.getCurrentSession()
    .createSQLQuery("SELECT * FROM some_data where foo = :foo order by bar
           LIMIT :from , :page")
    .addScalar(..)
    .setInteger("page", PAGE_SIZE)
    .setInteger("from", (i*PAGE_SIZE))
    ... // set other params 
    .list();

My mapping class has setters/getters for the blob object as

void setSomeBlob(Blob blob){
    this.someByteArray = this.toByteArray(blob)
}

void Blob getSomeBlob(){
    return Hibernate.createBlob(someByteArray)
}
  • 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-24T17:56:09+00:00Added an answer on May 24, 2026 at 5:56 pm

    Turn on bound parameters logging (you can do that by setting “org.hibernate.type” log level to “TRACE”) to see what specifically is being updated.

    Most likely you’re modifying the entities after they’ve been loaded – either explicitly or implicitly (e.g. returning different value from getter or using a default value somewhere).

    Another possibility is that you’ve recently altered (one of) the table(s) you’re selecting from and column default in the table doesn’t match default value in the entity.

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

Sidebar

Related Questions

I'm trying to implement some simple paging, based on How do I do pagination
I am trying to implement simple paging on my sharepoint webpart. I have a
Trying to implement the following behavior on an iPad. I have a map-centric application
I'm trying to implement paging in a custom ListAdapter. Right now I'm just making
im trying to implement some behaviors when a mapview element scrolls... by coding a
Im trying to implement an Observer/Observable pattern on an EC2 instance. I have been
i'm trying to implement paging in xml using this code and got around to
I'm trying to implement a paging and sorting list in ASP.NET MVC without using
I am trying to implement paging across ajax calls. The page should not refresh
I am trying to implement paging in PHP, using Json. I need the data

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.