CrudRepository and Hibernate: save(List) vs save(Entity) in transaction

后端 未结 3 681
渐次进展
渐次进展 2020-12-14 06:54

Would it make any difference if I do:

@Transactional
public void processData() {
    List entities = ....;
    MyEntityRepository.save(entiti         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-14 07:36

    For SpringData Jpa, a cleaner approach will be to use repository.saveAll instead of a forloop with repository.save. saveAll will automatically iterate through the list and save it.

    saveAll is a part of JpaRepository, so no need to define any method.

提交回复
热议问题