ritratt
ritratt

Reputation: 1858

How to save multiple rows using single DB connection with Micronaut?

Using Micronaut-Data 4.6.x. I'm trying to persist multiple rows to my table.

@JdbcRepository(dialect = Dialect.POSTGRES)
public interface MyRepository extends PageableRepository<Foo, Long> {
}

// And then I call the `saveAll` to save multiple rows from somewhere else
public void saveData(List<Foo> lostOfData) {
  myRepository.saveAll(lotsOfData);
}

I expected Micronaut to do a batch insert using a single connection+transaction. However, it turns out it not only does one insert per element of Foo but it also uses an individual DB connection. This results in performance issues as well as a starved connection pool.

I checked the docs and couldn't find a way to do this without writing my own queries, but then that defeats the purpose of using out of the box features that Micronaut Data provides.

Am I missing something? How do I save all this data using a single batch insert and a single DB connection?

Upvotes: 0

Views: 57

Answers (0)

Related Questions