Skip to content
Advertisement

Batch insert entities to DB (Quarkus, Hibernate)

First off: I’m not used to Quarkus or Hibernate (I’m pretty much all .net)

Problem:

My service receives a list of ~10k (Would guess thats the most common number). This comes via a resource endpoint, and it takes +10s for it to complete, Far to long. And the service is unresponsive.

JavaScript

The statusDao.Create() is annotated with @Transactional:

DAO is @ApplicationScoped

And this EM is:

JavaScript

statusDao.Create():

JavaScript

I’ve been reading a lot of posts about this, and many of them suggests this property, and split the persist loop to be the same as the batch size: quarkus.hibernate-orm.jdbc.statement-batch-size

Problem is, when I add it to the application.properties i get this varning:

Cannot resolve configuration item ‘statement-batch-size’

I’ve spent almost a day trying to find solutions on how to speed things up, anything obvious that I’ve missed here?

And/or:

Can I wrap the call from the service to the dao in some sort of magical fire and forget call built into Quarkus or Vert.x?

Advertisement

Answer

Hibernate keeps all entities that you persist in the persistence context so you will acquire more and more memory which might lead to bad performance. If you do not need these entities anymore as it seems, you can flush and clear them out in e.g. batches of 50 items.

JavaScript
Advertisement