Skip to content

Commit 8668f8e

Browse files
committed
Bulk updates
1 parent 9c3e29a commit 8668f8e

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

HibernateSpringBootBulkUpdates/src/main/java/com/bookstore/repository/AuthorRepository.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
public interface AuthorRepository extends JpaRepository<Author, Long> {
1616

1717
@Transactional(readOnly = true)
18-
@QueryHints(value = @QueryHint(name = HINT_PASS_DISTINCT_THROUGH,
19-
value = "false"))
18+
@QueryHints(value = @QueryHint(name = HINT_PASS_DISTINCT_THROUGH, value = "false"))
2019
@Query("SELECT DISTINCT a FROM Author a JOIN FETCH a.books b WHERE a.age > ?1")
2120
List<Author> findGtGivenAge(int age);
2221

2322
@Transactional
2423
@Modifying(flushAutomatically = true, clearAutomatically = true)
25-
@Query(value = "UPDATE author SET age = age + 1, version = version + 1",
26-
nativeQuery = true)
24+
@Query(value = "UPDATE Author a SET a.age = a.age + 1, a.version = a.version + 1")
2725
public int updateInBulk();
2826

2927
@Transactional

HibernateSpringBootBulkUpdates/src/main/java/com/bookstore/repository/BookRepository.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ public interface BookRepository extends JpaRepository<Book, Long> {
1414

1515
@Transactional
1616
@Modifying(flushAutomatically = true, clearAutomatically = true)
17-
@Query(value = "UPDATE book SET isbn='None', version=version + 1",
18-
nativeQuery = true)
17+
@Query(value = "UPDATE Book b SET b.isbn='None', b.version=b.version + 1")
1918
public int updateInBulk();
2019

2120
@Transactional

0 commit comments

Comments
 (0)