Skip to content

Commit 98b53f9

Browse files
committed
Reproducing the error from spring-projects#2564.
I tried to reproduce the error mentioned in spring-projects#2564 but I can't.
1 parent 65d524e commit 98b53f9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java

+20
Original file line numberDiff line numberDiff line change
@@ -2968,6 +2968,26 @@ void complexWithNativeStatement() {
29682968
assertThat(foundData).containsExactly("joachim", "dave", "kevin");
29692969
}
29702970

2971+
@Test
2972+
void nativeQueryWithSpELStatementTest() {
2973+
2974+
String exmapleFirstName = "Peter";
2975+
User firstPeter = new User(exmapleFirstName, "2", "[email protected]");
2976+
repository.save(firstPeter);
2977+
2978+
User secondPeter = new User(exmapleFirstName, "2", "[email protected]");
2979+
repository.save(secondPeter);
2980+
2981+
User firstDiego = new User("Diego", "2", "[email protected]");
2982+
repository.save(secondPeter);
2983+
2984+
User exampleUser = new User(exmapleFirstName, "IGNORE", "[email protected]");
2985+
List<User> foundData = repository.nativeQueryWithSpELStatement(exampleUser);
2986+
2987+
System.out.println(foundData);
2988+
assertThat(foundData).hasSize(2);
2989+
}
2990+
29712991
private Page<User> executeSpecWithSort(Sort sort) {
29722992

29732993
flushTestUsers();

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java

+3
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,9 @@ List<String> findAllAndSortByFunctionResultNamedParameter(@Param("namedParameter
676676
nativeQuery = true)
677677
List<String> complexWithNativeStatement();
678678

679+
@Query(value = "SELECT c.* FROM SD_User c WHERE c.firstname = :#{#example.firstname}", nativeQuery = true)
680+
List<User> nativeQueryWithSpELStatement(User example);
681+
679682
interface RolesAndFirstname {
680683

681684
String getFirstname();

0 commit comments

Comments
 (0)