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?
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With