From b80794fc71dd60d47f85e22c28b51144853610e9 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Tue, 7 Jan 2025 14:45:46 +0100 Subject: [PATCH] make sure to disable validation while tests are running --- spring-data-jpa/pom.xml | 6 +++ .../jpa/repository/query/SimpleJpaQuery.java | 5 +++ ...raphRepositoryMethodsIntegrationTests.java | 2 + ...eLinkParentRepositoryIntegrationTests.java | 2 + ...itoryWithCompositeKeyIntegrationTests.java | 2 + .../EclipseLinkUserRepositoryFinderTests.java | 7 ++++ .../repository/UserRepositoryFinderTests.java | 7 ++-- .../query/EclipseLinkJpa21UtilsTests.java | 2 + ...aAnnotatedQueryMethodIntegrationTests.java | 2 + .../jpa/repository/sample/UserExcerptDto.java | 41 ++++++++++--------- 10 files changed, 52 insertions(+), 24 deletions(-) diff --git a/spring-data-jpa/pom.xml b/spring-data-jpa/pom.xml index f3823eba35..fba223beb2 100644 --- a/spring-data-jpa/pom.xml +++ b/spring-data-jpa/pom.xml @@ -98,6 +98,12 @@ junit-platform-launcher test + + org.junit-pioneer + junit-pioneer + 2.3.0 + test + org.hsqldb diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/SimpleJpaQuery.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/SimpleJpaQuery.java index 16fa3c30e0..1fc5c31663 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/SimpleJpaQuery.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/SimpleJpaQuery.java @@ -18,6 +18,7 @@ import jakarta.persistence.EntityManager; import jakarta.persistence.Query; +import org.springframework.core.SpringProperties; import org.springframework.data.jpa.repository.QueryRewriter; import org.springframework.data.repository.query.RepositoryQuery; import org.springframework.data.repository.query.ValueExpressionDelegate; @@ -84,6 +85,10 @@ private void validateQuery(String query, String errorMessage, Object... argument return; } + if(SpringProperties.getFlag("spring.jpa.query.validation.disbaled")) { + return; + } + EntityManager validatingEm = null; try { diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/EclipseLinkEntityGraphRepositoryMethodsIntegrationTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/EclipseLinkEntityGraphRepositoryMethodsIntegrationTests.java index e0d21dc716..17d6e7771f 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/EclipseLinkEntityGraphRepositoryMethodsIntegrationTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/EclipseLinkEntityGraphRepositoryMethodsIntegrationTests.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junitpioneer.jupiter.SetSystemProperty; import org.springframework.test.context.ContextConfiguration; /** @@ -24,6 +25,7 @@ * @author Christoph Strobl */ @ContextConfiguration("classpath:eclipselink.xml") +@SetSystemProperty(key = "spring.jpa.query.validation.disbaled", value = "true") class EclipseLinkEntityGraphRepositoryMethodsIntegrationTests extends EntityGraphRepositoryMethodsIntegrationTests { diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/EclipseLinkParentRepositoryIntegrationTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/EclipseLinkParentRepositoryIntegrationTests.java index 06d1575fd5..52a8dad60f 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/EclipseLinkParentRepositoryIntegrationTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/EclipseLinkParentRepositoryIntegrationTests.java @@ -15,9 +15,11 @@ */ package org.springframework.data.jpa.repository; +import org.junitpioneer.jupiter.SetSystemProperty; import org.springframework.test.context.ContextConfiguration; @ContextConfiguration("classpath:eclipselink.xml") +@SetSystemProperty(key = "spring.jpa.query.validation.disbaled", value = "true") class EclipseLinkParentRepositoryIntegrationTests extends ParentRepositoryIntegrationTests { } diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/EclipseLinkRepositoryWithCompositeKeyIntegrationTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/EclipseLinkRepositoryWithCompositeKeyIntegrationTests.java index 82ca0c59a9..eba90ffcfb 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/EclipseLinkRepositoryWithCompositeKeyIntegrationTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/EclipseLinkRepositoryWithCompositeKeyIntegrationTests.java @@ -15,6 +15,7 @@ */ package org.springframework.data.jpa.repository; +import org.junitpioneer.jupiter.SetSystemProperty; import org.springframework.context.annotation.ImportResource; import org.springframework.test.context.ContextConfiguration; @@ -24,6 +25,7 @@ * @author Mark Paluch */ @ContextConfiguration +@SetSystemProperty(key = "spring.jpa.query.validation.disbaled", value = "true") class EclipseLinkRepositoryWithCompositeKeyIntegrationTests extends RepositoryWithIdClassKeyTests { @ImportResource({ "classpath:infrastructure.xml", "classpath:eclipselink.xml" }) diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/EclipseLinkUserRepositoryFinderTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/EclipseLinkUserRepositoryFinderTests.java index 18e0570de8..07953bf97f 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/EclipseLinkUserRepositoryFinderTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/EclipseLinkUserRepositoryFinderTests.java @@ -16,6 +16,7 @@ package org.springframework.data.jpa.repository; import org.junit.jupiter.api.Disabled; +import org.junitpioneer.jupiter.SetSystemProperty; import org.springframework.test.context.ContextConfiguration; /** @@ -26,6 +27,7 @@ * @author Greg Turnquist */ @ContextConfiguration("classpath:eclipselink-h2.xml") +@SetSystemProperty(key = "spring.jpa.query.validation.disbaled", value = "true") class EclipseLinkUserRepositoryFinderTests extends UserRepositoryFinderTests { @Disabled @@ -40,4 +42,9 @@ void executesInKeywordForPageCorrectly() {} @Override void rawMapProjectionWithEntityAndAggregatedValue() {} + @Disabled + @Override + void testQueryWithCTE() { + super.testQueryWithCTE(); + } } diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryFinderTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryFinderTests.java index 34bc59c4d0..ecc14cd3d1 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryFinderTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryFinderTests.java @@ -435,11 +435,10 @@ void dtoMultiselectProjectionShouldApplyConstructorExpressionRewriting() { } @Test // GH-3726 - void xxx() { - - Page dtos = userRepository.findWithCTE(PageRequest.of(0, 1)); - System.out.println("dtos: " + dtos); + void testQueryWithCTE() { + Page result = userRepository.findWithCTE(PageRequest.of(0, 1)); + assertThat(result.getTotalElements()).isEqualTo(3); } @Test // GH-3076 diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkJpa21UtilsTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkJpa21UtilsTests.java index bd97fbb600..d87bdf8034 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkJpa21UtilsTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkJpa21UtilsTests.java @@ -15,10 +15,12 @@ */ package org.springframework.data.jpa.repository.query; +import org.junitpioneer.jupiter.SetSystemProperty; import org.springframework.test.context.ContextConfiguration; /** * @author Christoph Strobl */ @ContextConfiguration("classpath:eclipselink.xml") +@SetSystemProperty(key = "spring.jpa.query.validation.disbaled", value = "true") class EclipseLinkJpa21UtilsTests extends Jpa21UtilsTests {} diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkMetaAnnotatedQueryMethodIntegrationTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkMetaAnnotatedQueryMethodIntegrationTests.java index df7b27f9d9..8427549b20 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkMetaAnnotatedQueryMethodIntegrationTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/EclipseLinkMetaAnnotatedQueryMethodIntegrationTests.java @@ -33,6 +33,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junitpioneer.jupiter.SetSystemProperty; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -69,6 +70,7 @@ @ExtendWith(SpringExtension.class) @ContextConfiguration @Transactional +@SetSystemProperty(key = "spring.jpa.query.validation.disbaled", value = "true") class EclipseLinkMetaAnnotatedQueryMethodIntegrationTests { @Autowired RoleRepositoryWithMeta repository; diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/sample/UserExcerptDto.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/sample/UserExcerptDto.java index 5e615573a2..af9e522267 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/sample/UserExcerptDto.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/sample/UserExcerptDto.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,32 +16,33 @@ package org.springframework.data.jpa.repository.sample; /** + * Hibernate is still a bit picky on records so let's use a class, just in case. + * * @author Christoph Strobl - * @since 2025/01 */ public class UserExcerptDto { - String firstname; - String lastname; + private String firstname; + private String lastname; - public UserExcerptDto(String firstname, String lastname) { - this.firstname = firstname; - this.lastname = lastname; - } + public UserExcerptDto(String firstname, String lastname) { + this.firstname = firstname; + this.lastname = lastname; + } - public String getFirstname() { - return firstname; - } + public String getFirstname() { + return firstname; + } - public void setFirstname(String firstname) { - this.firstname = firstname; - } + public void setFirstname(String firstname) { + this.firstname = firstname; + } - public String getLastname() { - return lastname; - } + public String getLastname() { + return lastname; + } - public void setLastname(String lastname) { - this.lastname = lastname; - } + public void setLastname(String lastname) { + this.lastname = lastname; + } }