0

Im using the saveAll method by spring-data-jpa.

I know that when i update an entity, hibernate needs to re-attach the detached entity and thats why before the update it executes select statements.

But when i try to update about 10.000 entity it means also 10.000 select will be executed which is a performance issue.

Isnt there any way re-attach that detached entites as bulk?

erdem
  • 103
  • 1
  • 11

1 Answers1

0

The Hibernate does not trigger a select query for update method. It is the merge that triggers an extra select to avoid duplicate record error(NonUniqueObjectException). So, you can use update to persist the detached entity.

This blog by @vlad-mihalcea explains the behavior of different methods

null
  • 548
  • 3
  • 14
  • spring-data checks the entity is new or not, if the entity will be updated (has ID), the merge method is called and that would trigger select query. – erdem Sep 17 '21 at 08:00