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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:34:27+00:00 2026-06-05T14:34:27+00:00

I use OpenJPA 2.2.0 on WebSphere Application Server 8 with a MySQL 5.0 DB.

  • 0

I use OpenJPA 2.2.0 on WebSphere Application Server 8 with a MySQL 5.0 DB.

I have a list of objects which I want to merge into the DB.

it’s like:

for (Object ob : list) {
            Long start = Calendar.getInstance().getTimeInMillis();
            em = factory.createEntityManager();
            em.getTransaction().begin();

            em.merge(ob);

            em.getTransaction().commit();
            em.close();
            Long end = Calendar.getInstance().getTimeInMillis();
            Long diff = end - start;
            LOGGER.info("Time: " + diff);
        }

When I run this loop I need about 300-600 Milliseconds to merge one object. When I delete the line “em.merge(ob);” then I need “0” Milliseconds to iterate over 1 List Object.

So my question is: What can I do to improve the time to merge one object?

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-05T14:34:28+00:00Added an answer on June 5, 2026 at 2:34 pm

    You can try starting the transaction before iteration & then commiting it afterwards within a single transaction. So, basically you are creating a batch which would be merged/persisted on commit.

    Also, you can limit the number of objects in a batch to be processed at a time & can explicitly flush the changes into database.

    Here, you are initiating a transaction & commiting it in each iteration and also creating/closing entity manager each time, will affect performance for numerous data.

    It will be something like below code.

    em = factory.createEntityManager();
    em.getTransaction().begin();
    int i = 0;
    
       for (Object ob : list) {
           Long start = Calendar.getInstance().getTimeInMillis();
    
           em.merge(ob);
    
           Long end = Calendar.getInstance().getTimeInMillis();
           Long diff = end - start;
           LOGGER.info("Time: " + diff);
    
           /*BATCH_SIZE is the number of entities 
                that will be persisted/merged at once */
    
           if(i%BATCH_SIZE == 0){    
               em.flush();
               em.clear(); 
           }
    
           i++;
       }
    
    em.getTransaction().commit();
    em.close();
    

    Here, you can also rollback the whole transaction if any of the object fails to persist/merge.

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

Sidebar

Related Questions

Use case: we have some project meta-data files which we want tracked, but are
We have to rename persistence.xml to fool WebSphere 7 not to use its built-in
I'm using WebSphere 7 and their JPA 2.0 implementation which is based on OpenJPA,
Use Html element SELECT in aspx page like: <SELECT id=MySelection name=MySelection runat=server DataValueField=ID DataTextField=Name></SELECT>
I am new to openJPA. I have a scenario where, depending upon the server
We have a batch application using OpenJPA. We are specifying all the DB connection
I want to not use the built in Websphere 7 jpa plugin, instead use
I'm using OpenJPA and want to configure it to use Autocommit on every write/insert
I have made use of the following JPA implementations: Hibernate, Toplink, OpenJPA Each of
Use case: I've just entered insert mode, and typed some text. Now I want

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.