使用JPA EntityManager批量插入 [英] Batch inserts using JPA EntityManager

查看:855
本文介绍了使用JPA EntityManager批量插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法可以使用JPA EntityManager来批量插入。我知道没有直接的方法可以达到这个目的,但必须有一些方法来实现这个机制。



实际上,对于每次插入操作,我需要300毫秒,这是我想要的减少使用批量插入而不是单个插入。



这是我正在使用的单个插入执行代码

  @PersistenceContext(unitName =testing)
EntityManager eM;

Query querys = this.eM.createNativeQuery(insertQuery);
for(String s:someList){
//设置参数
querys.executeUpdate();
}

提前致谢。

例如,文章解释了如何使用EclipseLink JPA 2.3和Oracle数据库启用批量写入(优化#8)。查看特定环境中的类似配置参数。


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.

这篇关于使用JPA EntityManager批量插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆