DATAJPA-430 - Tweaks to be compatible with Hibernate 4.3.
Latest Hibernate 4.3 releases have changes some behavior and internals slightly. Adapted the test cases accordingly and added another guard in JpaMetamodelEntityInformation to adhere to the new behavior. Added build profile to be able to build against Hibernate 4.3.
This commit is contained in:
10
pom.xml
10
pom.xml
@@ -35,13 +35,19 @@
|
||||
<profile>
|
||||
<id>hibernate-41</id>
|
||||
<properties>
|
||||
<hibernate>4.1.11.Final</hibernate>
|
||||
<hibernate>4.1.12.Final</hibernate>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>hibernate-42</id>
|
||||
<properties>
|
||||
<hibernate>4.2.0.Final</hibernate>
|
||||
<hibernate>4.2.7.SP1</hibernate>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>hibernate-43</id>
|
||||
<properties>
|
||||
<hibernate>4.3.0.CR2</hibernate>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
@@ -28,6 +28,7 @@ import javax.persistence.metamodel.IdentifiableType;
|
||||
import javax.persistence.metamodel.ManagedType;
|
||||
import javax.persistence.metamodel.Metamodel;
|
||||
import javax.persistence.metamodel.SingularAttribute;
|
||||
import javax.persistence.metamodel.Type;
|
||||
import javax.persistence.metamodel.Type.PersistenceType;
|
||||
|
||||
import org.springframework.beans.BeanWrapper;
|
||||
@@ -225,17 +226,23 @@ public class JpaMetamodelEntityInformation<T, ID extends Serializable> extends J
|
||||
Class<?> idType;
|
||||
|
||||
try {
|
||||
idType = type.getIdType().getJavaType();
|
||||
Type<?> idType2 = type.getIdType();
|
||||
idType = idType2 == null ? fallbackIdTypeLookup(type) : idType2.getJavaType();
|
||||
} catch (IllegalStateException e) {
|
||||
// see https://hibernate.onjira.com/browse/HHH-6951
|
||||
IdClass annotation = AnnotationUtils.findAnnotation(type.getJavaType(), IdClass.class);
|
||||
idType = annotation == null ? null : annotation.value();
|
||||
idType = fallbackIdTypeLookup(type);
|
||||
}
|
||||
|
||||
this.idType = idType;
|
||||
return idType;
|
||||
}
|
||||
|
||||
private static Class<?> fallbackIdTypeLookup(IdentifiableType<?> type) {
|
||||
|
||||
IdClass annotation = AnnotationUtils.findAnnotation(type.getJavaType(), IdClass.class);
|
||||
return annotation == null ? null : annotation.value();
|
||||
}
|
||||
|
||||
public SingularAttribute<? super T, ?> getSimpleIdAttribute() {
|
||||
return attributes.iterator().next();
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.hibernate.Version;
|
||||
import org.hibernate.ejb.HibernateQuery;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -105,12 +106,12 @@ public class PartTreeJpaQueryIntegrationTests {
|
||||
|
||||
Query query = jpaQuery.createQuery(new Object[] { "Matthews", new PageRequest(0, 1) });
|
||||
|
||||
HibernateQuery hibernateQuery = getValue(query, "h.target.val$jpaqlQuery");
|
||||
HibernateQuery hibernateQuery = getValue(query, "h.target." + (isHibernate43() ? "jpqlQuery" : "val$jpaqlQuery"));
|
||||
assertThat(hibernateQuery.getHibernateQuery().getQueryString(), endsWith("firstname=:param0"));
|
||||
|
||||
query = jpaQuery.createQuery(new Object[] { null, new PageRequest(0, 1) });
|
||||
|
||||
hibernateQuery = getValue(query, "h.target.val$jpaqlQuery");
|
||||
hibernateQuery = getValue(query, "h.target." + (isHibernate43() ? "jpqlQuery" : "val$jpaqlQuery"));
|
||||
assertThat(hibernateQuery.getHibernateQuery().getQueryString(), endsWith("firstname is null"));
|
||||
}
|
||||
|
||||
@@ -140,6 +141,10 @@ public class PartTreeJpaQueryIntegrationTests {
|
||||
return (T) result;
|
||||
}
|
||||
|
||||
private static boolean isHibernate43() {
|
||||
return Version.getVersionString().startsWith("4.3");
|
||||
}
|
||||
|
||||
interface UserRepository extends Repository<User, Long> {
|
||||
|
||||
Page<User> findByFirstname(String firstname, Pageable pageable);
|
||||
|
||||
Reference in New Issue
Block a user