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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:49:33+00:00 2026-05-12T11:49:33+00:00

I just jumped on a feature written by someone else that seems slightly inefficient,

  • 0

I just jumped on a feature written by someone else that seems slightly inefficient, but my knowledge of JPA isn’t that good to find a portable solution that’s not Hibernate specific.

In a nutshell the Dao method called within a loop to insert each one of the new entities does a “entityManager.merge(object);”.

Isnt’ there a way defined in the JPA specs to pass a list of entities to the Dao method and do a bulk / batch insert instead of calling merge for every single object?

Plus since the Dao method is annotated w/ “@Transactional” I’m wondering if every single merge call is happening within its own transaction… which would not help performance.

Any idea?

  • 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-12T11:49:33+00:00Added an answer on May 12, 2026 at 11:49 am

    No there is no batch insert operation in vanilla JPA.

    Yes, each insert will be done within its own transaction. The @Transactional attribute (with no qualifiers) means a propagation level of REQUIRED (create a transaction if it doesn’t exist already). Assuming you have:

    public class Dao {
      @Transactional
      public void insert(SomeEntity entity) {
        ...
      }
    }
    

    you do this:

    public class Batch {
      private Dao dao;
    
      @Transactional
      public void insert(List<SomeEntity> entities) {
        for (SomeEntity entity : entities) {
          dao.insert(entity);
        }
      }
    
      public void setDao(Dao dao) {
        this.dao = dao;
      }
    }
    

    That way the entire group of inserts gets wrapped in a single transaction. If you’re talking about a very large number of inserts you may want to split it into groups of 1000, 10000 or whatever works as a sufficiently large uncommitted transaction may starve the database of resources and possibly fail due to size alone.

    Note: @Transactional is a Spring annotation. See Transactional Management from the Spring Reference.

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

Sidebar

Related Questions

I just jumped on to a project that was started buy someone else and
Just wondering how I can make my app open automatically at login, but make
Just wondering if the following is considered to be good programming practice or not?
Just to make sure I'm understanding shallow copies of reference types correctly and that
Just looking for a good PHP Image Library, I want to display images with
Just a thing that annoys me. When I right click on a method name
I have just jumped into the Blackberry development arena... I am trying one example
I am very used to javascript and php programing, and I just jumped into
EDIT: 64 or 128 bit would also work. My brain just jumped to 32bit
I understand that I need to use LoadLibrary(). But what other steps do 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.