micronaut-projects / micronaut-data

Ahead of Time Data Repositories
Apache License 2.0
465 stars 197 forks source link

Lack of Batch Update possibilities #601

Closed ckosmowski closed 3 years ago

ckosmowski commented 4 years ago

Thanks for reporting an issue, please review the task list below before submitting the issue. Your issue report will be closed if the issue is incomplete and the below tasks not completed.

NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on Stack Overflow (https://stackoverflow.com/tags/micronaut) or Gitter (https://gitter.im/micronautfw/). DO NOT use the issue tracker to ask questions.

Task List

Steps to Reproduce

  1. Create a Repository for a simple entity with multiple fields
  2. Try to find a way of batch updating multiple of those fields at once

Expected Behaviour

i.e:

public void updateByTitleInListAndActiveTrue(List<String> title, String fieldToUpdate1, String fieldToUpdate2);

This results in an implemented method that yields a broken SQL Statement containing a comma behind the first question mark:

UPDATE `Table` SET `fieldToUpdate1`=?, WHERE (title IN(?,?) AND valid = TRUE )

We tried to workaround this by two methods like this, and executing them one after the other:

public void updateByTitleInListAndActiveTrue(List<String> title, String fieldToUpdate1);
public void updateByTitleInListAndActiveTrue(List<String> title, String fieldToUpdate2);

This results in a broken query like this

UPDATE `Table` SET  WHERE (title IN(?,?) AND active = TRUE )

Using a custom query with @Query also seems to be no solution, because we cannot use Lists and the in() statement in there.

So the question is how to update multiple fields in multiple certain rows identified by a list in a batch.

Environment Information

Example Application

graemerocher commented 3 years ago

Relates to #690