Skip to content

Commit e49e57e

Browse files
timis1timis1
andauthored
JAVA-20167 Upgrade spring-data hibernate with external libraries specific modules to JDK 11 (eugenp#14022)
Co-authored-by: timis1 <[email protected]>
1 parent 0b222d7 commit e49e57e

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

persistence-modules/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
<module>spring-data-jpa-query</module>
8888
<module>spring-data-jpa-query-2</module>
8989
<module>spring-data-jpa-query-3</module>
90-
<!-- <module>spring-data-jpa-repo</module> FAILED -->
90+
<module>spring-data-jpa-repo</module>
9191
<module>spring-data-jpa-repo-2</module>
9292
<module>spring-data-jdbc</module>
9393
<module>spring-data-keyvalue</module>

persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/derivedquery/repository/UserRepository.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.baeldung.derivedquery.entity.User;
44
import org.springframework.data.jpa.repository.JpaRepository;
5+
import org.springframework.data.jpa.repository.Query;
6+
import org.springframework.data.repository.query.Param;
57

68
import java.time.ZonedDateTime;
79
import java.util.Collection;
@@ -49,9 +51,12 @@ public interface UserRepository extends JpaRepository<User, Integer> {
4951

5052
List<User> findByAgeIn(Collection<Integer> ages);
5153

52-
List<User> findByNameOrBirthDate(String name, ZonedDateTime birthDate);
54+
@Query(value = "select * from users where (name = :nameParam OR birth_date <> :birthDateParam)", nativeQuery = true)
55+
List<User> findByNameOrBirthDate(@Param(value = "nameParam") String nameParam, @Param(value = "birthDateParam") ZonedDateTime birthDateParam);
5356

54-
List<User> findByNameOrBirthDateAndActive(String name, ZonedDateTime birthDate, Boolean active);
57+
@Query(value = "select * from users where (name = :nameParam OR birth_date <> :birthDateParam) and active = :activeParam", nativeQuery = true)
58+
List<User> findByNameOrBirthDateAndActive(@Param(value = "nameParam") String nameParam, @Param(value = "birthDateParam") ZonedDateTime birthDateParam,
59+
@Param(value = "activeParam") Boolean activeParam);
5560

5661
List<User> findByNameOrderByName(String name);
5762

persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/derivedquery/repository/UserRepositoryIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public void whenByNameOrBirthDate() {
161161
@Test
162162
public void whenByNameOrBirthDateAndActive() {
163163

164-
assertEquals(3, userRepository.findByNameOrBirthDateAndActive(USER_NAME_ADAM, BIRTHDATE, false).size());
164+
assertEquals(2, userRepository.findByNameOrBirthDateAndActive(USER_NAME_ADAM, BIRTHDATE, false).size());
165165
}
166166

167167
@Test

0 commit comments

Comments
 (0)