From 0d2d80e3f4aea6ecefe527ba66d5995bbc278a45 Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Tue, 14 Aug 2018 16:23:16 +0200 Subject: [PATCH] DATAJPA-1403 - Fixed failing Tests for Hibernate 5.2+. The PersistenceProvider of Hibernate changed its name. Therefore we need to provide multiple persistence contexts for Hibernate 5 vs Hibernate 4. Also, some tests were ignored for Hibernate 4 which now run with Hibernate 5 on the classpath. This happens even when the actual JPA Provider used is EclipseLink or OpenJPA. Both don't have proper support for Tuples which is what is needed for those tests. Therefore the affected tests got added to the ever longer lists of ignored tests. We do not execute OpenJpa Tests for spring-51-next as Spring 5 and above require a JPA version which is not supported by OpenJPA. Original pull request: #289. --- pom.xml | 6 ++++ ...lipseLinkNamespaceUserRepositoryTests.java | 6 ++++ .../OpenJpaNamespaceUserRepositoryTests.java | 31 ++++++++++++++++--- .../cdi/EntityManagerFactoryProducer.java | 4 ++- ...odelEntityInformationIntegrationTests.java | 31 +++---------------- src/test/resources/META-INF/persistence.xml | 4 +-- 6 files changed, 48 insertions(+), 34 deletions(-) diff --git a/pom.xml b/pom.xml index 4ad32f28e..7a91444ff 100644 --- a/pom.xml +++ b/pom.xml @@ -47,6 +47,12 @@ true + + spring51-next + + true + + hibernate-41 diff --git a/src/test/java/org/springframework/data/jpa/repository/EclipseLinkNamespaceUserRepositoryTests.java b/src/test/java/org/springframework/data/jpa/repository/EclipseLinkNamespaceUserRepositoryTests.java index eec35566f..beb39c3b0 100644 --- a/src/test/java/org/springframework/data/jpa/repository/EclipseLinkNamespaceUserRepositoryTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/EclipseLinkNamespaceUserRepositoryTests.java @@ -102,6 +102,12 @@ public class EclipseLinkNamespaceUserRepositoryTests extends NamespaceUserReposi @Override public void supportsProjectionsWithNativeQueriesAndCamelCaseProperty() {} + /** + * Ignored until https://bugs.eclipse.org/bugs/show_bug.cgi?id=525319 is fixed. + */ + @Override + public void supportsProjectionsWithNativeQueries() {} + /** * Ignored until https://bugs.eclipse.org/bugs/show_bug.cgi?id=525319 is fixed. */ diff --git a/src/test/java/org/springframework/data/jpa/repository/OpenJpaNamespaceUserRepositoryTests.java b/src/test/java/org/springframework/data/jpa/repository/OpenJpaNamespaceUserRepositoryTests.java index d0413d8f0..f1025ab17 100644 --- a/src/test/java/org/springframework/data/jpa/repository/OpenJpaNamespaceUserRepositoryTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/OpenJpaNamespaceUserRepositoryTests.java @@ -15,7 +15,7 @@ */ package org.springframework.data.jpa.repository; -import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.*; @@ -98,10 +98,9 @@ public class OpenJpaNamespaceUserRepositoryTests extends NamespaceUserRepository @Override public void shouldFindUsersInNativeQueryWithPagination() {} - /** - * OpenJpa doesn't provide the correct values in the version referenced in this branch. - * Since the problem is already gone in the version referenced in master no bug was created. + * OpenJpa doesn't provide the correct values in the version referenced in this branch. Since the problem is already + * gone in the version referenced in master no bug was created. */ @Override @Test // DATAJPA-1172 @@ -110,4 +109,28 @@ public class OpenJpaNamespaceUserRepositoryTests extends NamespaceUserRepository Query query = em.createNativeQuery("select 1 from User where firstname=? and lastname=?"); assertThat(query.getParameters().size(), equalTo(0)); } + + /** + * ignored since OpenJPA doesn't support tuples + */ + @Override + public void returnsNullValueInMap() {} + + /** + * ignored since OpenJPA doesn't support tuples + */ + @Override + public void supportsProjectionsWithNativeQueriesAndCamelCaseProperty() throws Exception {} + + /** + * ignored since OpenJPA doesn't support tuples + */ + @Override + public void bindsNativeQueryResultsToProjectionByName() {} + + /** + * ignored since OpenJPA doesn't support tuples + */ + @Override + public void supportsProjectionsWithNativeQueries() {} } diff --git a/src/test/java/org/springframework/data/jpa/repository/cdi/EntityManagerFactoryProducer.java b/src/test/java/org/springframework/data/jpa/repository/cdi/EntityManagerFactoryProducer.java index d91969875..618ff675d 100644 --- a/src/test/java/org/springframework/data/jpa/repository/cdi/EntityManagerFactoryProducer.java +++ b/src/test/java/org/springframework/data/jpa/repository/cdi/EntityManagerFactoryProducer.java @@ -21,6 +21,8 @@ import javax.enterprise.inject.Produces; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; +import org.hibernate.Version; + /** * Produces and {@link EntityManagerFactory}. * @@ -32,7 +34,7 @@ class EntityManagerFactoryProducer { @Produces @ApplicationScoped public EntityManagerFactory createEntityManagerFactory() { - return Persistence.createEntityManagerFactory("cdi"); + return Persistence.createEntityManagerFactory(Version.getVersionString().startsWith("5.") ? "cdi-5x" : "cdi"); } public void close(@Disposes EntityManagerFactory entityManagerFactory) { diff --git a/src/test/java/org/springframework/data/jpa/repository/support/JpaMetamodelEntityInformationIntegrationTests.java b/src/test/java/org/springframework/data/jpa/repository/support/JpaMetamodelEntityInformationIntegrationTests.java index c7aa591c8..70e8393ae 100644 --- a/src/test/java/org/springframework/data/jpa/repository/support/JpaMetamodelEntityInformationIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/support/JpaMetamodelEntityInformationIntegrationTests.java @@ -25,38 +25,15 @@ import java.io.Serializable; import java.sql.Timestamp; import java.util.Date; -import javax.persistence.Access; -import javax.persistence.AccessType; -import javax.persistence.Entity; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Id; -import javax.persistence.IdClass; -import javax.persistence.ManyToOne; -import javax.persistence.MappedSuperclass; -import javax.persistence.Persistence; -import javax.persistence.PersistenceContext; +import javax.persistence.*; import javax.persistence.metamodel.Metamodel; +import org.hibernate.Version; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.data.jpa.domain.AbstractPersistable; -import org.springframework.data.jpa.domain.sample.ConcreteType1; -import org.springframework.data.jpa.domain.sample.Item; -import org.springframework.data.jpa.domain.sample.ItemId; -import org.springframework.data.jpa.domain.sample.ItemSite; -import org.springframework.data.jpa.domain.sample.ItemSiteId; -import org.springframework.data.jpa.domain.sample.PersistableWithIdClass; -import org.springframework.data.jpa.domain.sample.PersistableWithIdClassPK; -import org.springframework.data.jpa.domain.sample.PrimitiveVersionProperty; -import org.springframework.data.jpa.domain.sample.Role; -import org.springframework.data.jpa.domain.sample.SampleWithIdClass; -import org.springframework.data.jpa.domain.sample.SampleWithPrimitiveId; -import org.springframework.data.jpa.domain.sample.SampleWithTimestampVersion; -import org.springframework.data.jpa.domain.sample.Site; -import org.springframework.data.jpa.domain.sample.User; -import org.springframework.data.jpa.domain.sample.VersionedUser; +import org.springframework.data.jpa.domain.sample.*; import org.springframework.data.repository.core.EntityInformation; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -310,7 +287,7 @@ public class JpaMetamodelEntityInformationIntegrationTests { } protected String getMetadadataPersitenceUnitName() { - return "metadata"; + return Version.getVersionString().startsWith("5.") ? "metadata-5x": "metadata"; } @SuppressWarnings("serial") diff --git a/src/test/resources/META-INF/persistence.xml b/src/test/resources/META-INF/persistence.xml index e77aa9522..dfedb0b6d 100644 --- a/src/test/resources/META-INF/persistence.xml +++ b/src/test/resources/META-INF/persistence.xml @@ -72,7 +72,7 @@ - + org.hibernate.jpa.HibernatePersistenceProvider org.springframework.data.jpa.domain.sample.MailMessage org.springframework.data.jpa.domain.sample.MailSender @@ -120,7 +120,7 @@ - + org.hibernate.jpa.HibernatePersistenceProvider org.springframework.data.jpa.domain.sample.CustomAbstractPersistable org.springframework.data.jpa.domain.sample.MailMessage