Is there a way where we can use batch inserts using JPA EntityManager. I know there is no direct way to achieve this but there must be some way to achieve this mechanism.
Actually, for every insert operation it's taking me 300ms which I want to reduce using batch inserts instead of single inserts.
Here's code I am using currently executing for single inserts
@PersistenceContext(unitName = "testing")
EntityManager eM;
Query querys = this.eM.createNativeQuery(insertQuery);
for (String s : someList) {
//setting parameters
querys.executeUpdate();
}
Thanks in advance.
It is possible to perform batch writes using JPA, but it's highly dependent on the specific implementation of your persistence provider, database and JDBC driver. For example, this article explains how to enable batch writing (optimization #8) using EclipseLink JPA 2.3 and an Oracle database.Look for similar configuration parameters in your particular environment.