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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:06:22+00:00 2026-05-30T18:06:22+00:00

I am looking for a JPA-solution (vendor-independent) to execute a query in batches. The

  • 0

I am looking for a JPA-solution (vendor-independent) to execute a query in batches. The challenge is to make this performant as well as thread-safe.

Example query:

Query query = em.createQuery("select e from Entity e where e.property in :list");

The list is a collection of size between 1 and 385000. Hence, the requirement to batch this query.

Initial naive approach was to get a sublist from the original list and loop through until done. This was safe and working well except that it was not performant.

Second approach was to load everything from the list onto a temp table (permanent in existence, but used as a temporary table) and then use the original query and join with the temp table. This is definitely performant, but is not thread-safe as I need to clear the temp table after each batch and without having any thread id or something of that sort in the temp table its pretty unsafe (which is at the moment).

I would really appreciate suggestions to arrive at a performant and safe way to tackle this issue.

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-30T18:06:23+00:00Added an answer on May 30, 2026 at 6:06 pm

    First of all, the query is not valid JPQL, because it doesn’t have a select clause.

    Second, it should be where e.property in (:list).

    Your strategy of populating a temp table looks fine to me. You could just make it contain an additional uuid column, and generate a new UUID each time you want to perform such a query:

    • generate a UUID
    • insert all the elements of the list in the table, with the uuid column set to the generated UUID
    • execute a query such as select e from Entity e, TempEntity temp where e.property = temp.property and temp.uuid = :uuid
    • execute a query to delete all the rows from the temp table (not absolutely necessary): delete from TempEntity temp where temp.uuid :uuid
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for JPA 2 criteria equivalent of this JPQL query : select e
Looking to do a bit of refactoring... Using NHibernate I have this query currently
I'm looking into integrating elasticsearch into my spring-jpa driven application. For this purpose the
By looking into the Open JPA website i've found that i can log the
Looking for best advice on how to do this: I have an insert like
I'm looking for the different ways to map an enum using JPA. I especially
I'm asking this question given my chosen development frameworks of JPA (Hibernate implementation of),
I'm looking for an easy way to extend existing JPA mapping. The idea is
I am looking into Spring Data JPA. Consider the below example where I will
This is the same question as: How to dynamically generate SQL query based on

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.