diff --git a/Jenkinsfile b/Jenkinsfile index 199996f06..8c14e1abf 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -53,6 +53,23 @@ pipeline { } parallel { + stage("test: baseline (hibernate 6.1)") { + agent { + label 'data' + } + options { timeout(time: 30, unit: 'MINUTES')} + environment { + ARTIFACTORY = credentials("${p['artifactory.credentials']}") + } + steps { + script { + docker.image(p['docker.java.next.image']).inside(p['docker.java.inside.docker']) { + sh 'PROFILE=all-dbs,hibernate-61 ci/test.sh' + sh "ci/clean.sh" + } + } + } + } stage("test: baseline (next)") { agent { label 'data' diff --git a/pom.xml b/pom.xml index 48280a3f7..849cb3537 100644 --- a/pom.xml +++ b/pom.xml @@ -54,6 +54,12 @@ + + hibernate-61 + + 6.1.7.Final + + all-dbs diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/procedures/PostgresStoredProcedureIntegrationTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/procedures/PostgresStoredProcedureIntegrationTests.java index b6997ef25..10c07c1a7 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/procedures/PostgresStoredProcedureIntegrationTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/procedures/PostgresStoredProcedureIntegrationTests.java @@ -16,7 +16,7 @@ package org.springframework.data.jpa.repository.procedures; -import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.*; import jakarta.persistence.Entity; import jakarta.persistence.EntityManagerFactory; @@ -36,7 +36,6 @@ import java.util.Properties; import javax.sql.DataSource; import org.hibernate.dialect.PostgreSQLDialect; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.postgresql.ds.PGSimpleDataSource; @@ -48,6 +47,7 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.query.Procedure; +import org.springframework.data.jpa.util.DisabledOnHibernate62; import org.springframework.jdbc.datasource.init.DataSourceInitializer; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean; @@ -68,7 +68,6 @@ import org.testcontainers.containers.PostgreSQLContainer; * @author Greg Turnquist * @author Yanming Zhou */ -@Disabled @Transactional @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = PostgresStoredProcedureIntegrationTests.Config.class) @@ -116,6 +115,7 @@ class PostgresStoredProcedureIntegrationTests { new Employee(4, "Gabriel")); } + @DisabledOnHibernate62 @Test // 2256 void testSingleEntityFromResultSet() { diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/support/HibernateJpaMetamodelEntityInformationIntegrationTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/support/HibernateJpaMetamodelEntityInformationIntegrationTests.java index 2628d87bf..0716d5e64 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/support/HibernateJpaMetamodelEntityInformationIntegrationTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/support/HibernateJpaMetamodelEntityInformationIntegrationTests.java @@ -15,7 +15,9 @@ */ package org.springframework.data.jpa.repository.support; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.data.jpa.util.DisabledOnHibernate61; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -26,11 +28,31 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; */ @ExtendWith(SpringExtension.class) @ContextConfiguration("classpath:infrastructure.xml") -class HibernateJpaMetamodelEntityInformationIntegrationTests - extends JpaMetamodelEntityInformationIntegrationTests { +class HibernateJpaMetamodelEntityInformationIntegrationTests extends JpaMetamodelEntityInformationIntegrationTests { @Override String getMetadadataPersistenceUnitName() { return "metadata-id-handling"; } + + @DisabledOnHibernate61 + @Test + @Override + void correctlyDeterminesIdValueForNestedIdClassesWithNonPrimitiveNonManagedType() { + super.correctlyDeterminesIdValueForNestedIdClassesWithNonPrimitiveNonManagedType(); + } + + @DisabledOnHibernate61 + @Test + @Override + void prefersPrivateGetterOverFieldAccess() { + super.prefersPrivateGetterOverFieldAccess(); + } + + @DisabledOnHibernate61 + @Test + @Override + void findsIdClassOnMappedSuperclass() { + super.findsIdClassOnMappedSuperclass(); + } } diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/util/DisabledOnHibernate61.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/util/DisabledOnHibernate61.java new file mode 100644 index 000000000..221083a12 --- /dev/null +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/util/DisabledOnHibernate61.java @@ -0,0 +1,36 @@ +/* + * Copyright 2015-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.jpa.util; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * Annotation to flag JUnit 5 test cases to ONLY activate when Hibernate 6.2 is on the classpath. + * + * @author Greg Turnquist + * @since 3.1 + */ +@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.ANNOTATION_TYPE }) +@Retention(RetentionPolicy.RUNTIME) +@ExtendWith(HibernateSupport.DisabledWhenHibernate61OnClasspath.class) +public @interface DisabledOnHibernate61 { + +} diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/util/DisabledOnHibernate62.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/util/DisabledOnHibernate62.java new file mode 100644 index 000000000..5ab5042a3 --- /dev/null +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/util/DisabledOnHibernate62.java @@ -0,0 +1,36 @@ +/* + * Copyright 2015-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.jpa.util; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * Annotation to flag JUnit 5 test cases to ONLY activate when Hibernate 6.1 is on the classpath. + * + * @author Greg Turnquist + * @since 3.1 + */ +@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.ANNOTATION_TYPE }) +@Retention(RetentionPolicy.RUNTIME) +@ExtendWith(HibernateSupport.DisabledWhenHibernate62OnClasspath.class) +public @interface DisabledOnHibernate62 { + +} diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/util/HibernateSupport.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/util/HibernateSupport.java new file mode 100644 index 000000000..3afeaa16b --- /dev/null +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/util/HibernateSupport.java @@ -0,0 +1,62 @@ +/* + * Copyright 2015-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.jpa.util; + +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.springframework.util.ClassUtils; + +/** + * JUnit 5 utilities to support conditional test cases based upon Hibernate classpath settings. + * + * @author Greg Turnquist + * @since 3.1 + */ +abstract class HibernateSupport { + + /** + * {@literal org.hibernate.dialect.PostgreSQL91Dialect} is deprecated in Hibernate 6.1 and fully removed in Hibernate + * 6.2, making it a perfect detector between the two. + */ + private static final boolean HIBERNATE_61_ON_CLASSPATH = ClassUtils + .isPresent("org.hibernate.dialect.PostgreSQL91Dialect", HibernateSupport.class.getClassLoader()); + + private static final boolean HIBERNATE_62_ON_CLASSPATH = !HIBERNATE_61_ON_CLASSPATH; + + static class DisabledWhenHibernate61OnClasspath implements ExecutionCondition { + + @Override + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) { + + return HibernateSupport.HIBERNATE_61_ON_CLASSPATH + ? ConditionEvaluationResult.disabled("Disabled because Hibernate 6.1 is on the classpath") + : ConditionEvaluationResult.enabled("NOT disabled because Hibernate 6.2 is on the classpath"); + } + } + + static class DisabledWhenHibernate62OnClasspath implements ExecutionCondition { + + @Override + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) { + + return HibernateSupport.HIBERNATE_62_ON_CLASSPATH + ? ConditionEvaluationResult.disabled("Disabled because Hibernate 6.2 is on the classpath") + : ConditionEvaluationResult.enabled("NOT disabled because Hibernate 6.1 is on the classpath"); + } + + } +}