JPA/Hibernate批量插入速度很慢 [英] JPA/Hibernate bulk inserts slow

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

问题描述

我正在使用Hibernate作为提供程序使用JPA进行批量插入.该数据库是Oracle.它创建了一个序列生成器,并且每次执行插入操作时都会向序列生成器查询nextval.如果我要进行1K次插入,它将击中序列生成器1K次.如果我想坚持使用JPA,有什么方法可以加快速度?

I'm doing bulk inserts with JPA using Hibernate as my provider. The DB is Oracle. It created a sequence generator, and each time it does an insert it queries the sequence generator for nextval. If I'm doing 1K inserts, it will hit the sequence generator 1K times. Any way to speed this up, if I want to stick with JPA?

推荐答案

在JPA @SequenceGenerator中使用allocationSize.

请参见此示例,将其设置为150:

See this example, where it is set to 150:

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "MY_ENTITY_SEQ")
@SequenceGenerator(name = "MY_ENTITY_SEQ", sequenceName = "MY_ENTITY_SEQ", allocationSize = 150)
@Column(name = "MY_ENTITY", nullable = false)
private Long id;

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

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