diff --git a/Jenkinsfile b/Jenkinsfile index 46c74c42d..e345657e1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -53,6 +53,23 @@ pipeline { } parallel { + stage("test: baseline (hibernate 6.2)") { + 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-62 ci/test.sh' + sh "ci/clean.sh" + } + } + } + } stage("test: baseline (next)") { agent { label 'data' diff --git a/pom.xml b/pom.xml index 522cc6dc9..aa83fb518 100644 --- a/pom.xml +++ b/pom.xml @@ -53,6 +53,12 @@ + + hibernate-62 + + 6.2.1.Final + + all-dbs diff --git a/spring-data-jpa/pom.xml b/spring-data-jpa/pom.xml index 6a4562132..9cb763199 100644 --- a/spring-data-jpa/pom.xml +++ b/spring-data-jpa/pom.xml @@ -23,6 +23,27 @@ spring.data.jpa + + + hibernate-62 + + + org.eclipse.persistence + org.eclipse.persistence.jpa + ${eclipselink} + true + + + jakarta.persistence + jakarta.persistence-api + + + + + + + + @@ -137,6 +158,13 @@ + + org.eclipse.persistence + org.eclipse.persistence.jpa + ${eclipselink} + true + + ${hibernate.groupId}.orm hibernate-core @@ -149,7 +177,7 @@ - + ${hibernate.groupId}.orm hibernate-jpamodelgen @@ -170,13 +198,6 @@ ${jakarta-annotation-api} - - org.eclipse.persistence - org.eclipse.persistence.jpa - ${eclipselink} - true - - com.querydsl 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 f0259324c..560642b65 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; @@ -35,7 +35,7 @@ import java.util.Properties; import javax.sql.DataSource; -import org.hibernate.dialect.PostgreSQL91Dialect; +import org.hibernate.dialect.PostgreSQLDialect; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.postgresql.ds.PGSimpleDataSource; @@ -47,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; @@ -114,6 +115,7 @@ public class PostgresStoredProcedureIntegrationTests { new Employee(4, "Gabriel")); } + @DisabledOnHibernate62 @Test // 2256 void testSingleEntityFromResultSet() { @@ -201,7 +203,7 @@ public class PostgresStoredProcedureIntegrationTests { @Bean(initMethod = "start", destroyMethod = "stop") public PostgreSQLContainer container() { - return new PostgreSQLContainer<>("postgres:10.21") // + return new PostgreSQLContainer<>("postgres:9.6.12") // .withUsername("postgres"); } @@ -226,7 +228,7 @@ public class PostgresStoredProcedureIntegrationTests { Properties properties = new Properties(); properties.setProperty("hibernate.hbm2ddl.auto", "create"); - properties.setProperty("hibernate.dialect", PostgreSQL91Dialect.class.getCanonicalName()); + properties.setProperty("hibernate.dialect", PostgreSQLDialect.class.getCanonicalName()); factoryBean.setJpaProperties(properties); return factoryBean; 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 f11a30b9a..7143f89e8 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; @@ -33,4 +35,25 @@ public class HibernateJpaMetamodelEntityInformationIntegrationTests 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"); + } + + } +}