From 36078d85df6c44e7a72637f5b698375108cab661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Fri, 18 Aug 2023 17:20:27 +0200 Subject: [PATCH] Add a reproducer for spring-projects/spring-framework#29603 --- .../src/main/java/com/example/data/jpa/AuthorRepository.java | 3 +++ .../main/java/com/example/data/jpa/TransactionalRunner.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/data/data-jpa/src/main/java/com/example/data/jpa/AuthorRepository.java b/data/data-jpa/src/main/java/com/example/data/jpa/AuthorRepository.java index 794f72b6..0938b488 100644 --- a/data/data-jpa/src/main/java/com/example/data/jpa/AuthorRepository.java +++ b/data/data-jpa/src/main/java/com/example/data/jpa/AuthorRepository.java @@ -15,6 +15,9 @@ public interface AuthorRepository extends ListCrudRepository { @Query("SELECT a FROM Author a WHERE a.name = :name") Optional queryFindByName(String name); + @Query(value = "SELECT * FROM author WHERE name = :name", nativeQuery = true) + Optional nativeQueryFindByName(String name); + Stream findByNameContaining(String name); } diff --git a/data/data-jpa/src/main/java/com/example/data/jpa/TransactionalRunner.java b/data/data-jpa/src/main/java/com/example/data/jpa/TransactionalRunner.java index 85c520f2..dce41b64 100644 --- a/data/data-jpa/src/main/java/com/example/data/jpa/TransactionalRunner.java +++ b/data/data-jpa/src/main/java/com/example/data/jpa/TransactionalRunner.java @@ -52,7 +52,7 @@ private void deleteAll() { private void queryFindByName() { Author author1 = this.authorRepository.queryFindByName("Josh Long").orElse(null); - Author author2 = this.authorRepository.queryFindByName("Martin Kleppmann").orElse(null); + Author author2 = this.authorRepository.nativeQueryFindByName("Martin Kleppmann").orElse(null); System.out.printf("queryFindByName(): author1 = %s%n", author1); System.out.printf("queryFindByName(): author2 = %s%n", author2);