persist multiple entities with reactive quarkus and hibernate/panache

88 views Asked by At

As a newcomer to reactive quarkus/hibernate/panache, i would appreciate your feedback on how to persist entities in a loop to the database.

Let's assume that at some point we have a list of departments and for each department we want to store a new Employee

for (Department dep: office.getDepartments()) {
    Employee emp = new Employee();
    emp.setName("...");
    emp.setDepartment(dep);
    emp.persistAndFlush(); //no return uni?
}
//more statements here that will eventually return a uni...

The problem here is how to handle the return uni inside the loop. The above statement returns a warning "Result of 'PanacheEntityBase.persistAndFlush()' is ignored Value is never used as Publisher". A return statement will break the loop.

Is there a persistAndFlushAll(List of entities) method ? I want to wait for each persist to make sure that each object is persisted correctly. I also noticed a combine method, but i am not sure how to use it.

Thank you very much for your replies.

0

There are 0 answers