From fc0b133bdb4aa5ea62a1f0a57d33cfb36efdd219 Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Fri, 24 Jul 2020 14:32:06 +0200 Subject: [PATCH] DATAJPA-1761 - Readds call to save for consistency with other Spring Data modules. --- src/main/asciidoc/jpa.adoc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/asciidoc/jpa.adoc b/src/main/asciidoc/jpa.adoc index f2bcffd2f..ac43e9009 100644 --- a/src/main/asciidoc/jpa.adoc +++ b/src/main/asciidoc/jpa.adoc @@ -911,11 +911,14 @@ class UserManagementImpl implements UserManagement { for (User user : userRepository.findAll()) { user.addRole(role); - // note that no call to "save" is necessary since the entities are attached to the EntityManager + userRepository.save(user); } } ---- -This example causes call to `addRoleToAllUsers(…)` to run inside a transaction (participating in an existing one or creating a new one if none are already running). The transaction configuration at the repositories is then neglected, as the outer transaction configuration determines the actual one used. Note that you must activate `` or use `@EnableTransactionManagement` explicitly to get annotation-based configuration of facades to work. This example assumes you use component scanning. +This example causes call to `addRoleToAllUsers(…)` to run inside a transaction (participating in an existing one or creating a new one if none are already running). The transaction configuration at the repositories is then neglected, as the outer transaction configuration determines the actual one used. Note that you must activate `` or use `@EnableTransactionManagement` explicitly to get annotation-based configuration of facades to work. +This example assumes you use component scanning. + +Note that the call to `save` is not strictly necessary from a JPA point of view, but should still be there in order to stay consistent to the repository abstraction offered by Spring Data. ==== [[transactional-query-methods]]