Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA/Hibernate bulk inserts slow

Tags:

hibernate

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?

like image 378
tbaz Avatar asked Dec 30 '22 01:12

tbaz


1 Answers

Use the allocationSize in the JPA @SequenceGenerator.

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;
like image 112
JavaRocky Avatar answered Jan 09 '23 09:01

JavaRocky