From 6d1bc47f06f2c283395b83458d5429aeaa7942cd Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Tue, 14 Aug 2018 13:08:02 +0200 Subject: [PATCH] DATAJPA-1392 - Allow lenient PersistentEntity lookup via JPA Metamodel. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JpaMetamodelMappingContext now overrides ….hasPersistentEntityFor(…) to fall back to a JPA Metamodel lookup check as only checking the cache might not be sufficient as it's not eagerly populated anymore. --- .../mapping/JpaMetamodelMappingContext.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/data/jpa/mapping/JpaMetamodelMappingContext.java b/src/main/java/org/springframework/data/jpa/mapping/JpaMetamodelMappingContext.java index 0450af7f3..61d882095 100644 --- a/src/main/java/org/springframework/data/jpa/mapping/JpaMetamodelMappingContext.java +++ b/src/main/java/org/springframework/data/jpa/mapping/JpaMetamodelMappingContext.java @@ -100,6 +100,15 @@ public class JpaMetamodelMappingContext return doFindPersistentPropertyPaths(type, predicate, it -> it.isEmbeddable()); } + /* + * (non-Javadoc) + * @see org.springframework.data.mapping.context.AbstractMappingContext#hasPersistentEntityFor(java.lang.Class) + */ + @Override + public boolean hasPersistentEntityFor(Class type) { + return super.hasPersistentEntityFor(type) || models.isMetamodelManagedType(type); + } + /** * A wrapper for a set of JPA {@link Metamodel} instances to simplify lookups of {@link JpaMetamodel} instances and * managed type checks. @@ -129,13 +138,23 @@ public class JpaMetamodelMappingContext } /** - * Retruns whether the given type is managed by one of the underlying {@link Metamodel} instances. + * Returns whether the given type is managed by one of the underlying {@link Metamodel} instances. * * @param type must not be {@literal null}. * @return */ public boolean isMetamodelManagedType(TypeInformation type) { - return getMetamodelFor(type.getType()) != null; + return isMetamodelManagedType(type.getType()); + } + + /** + * Returns whether the given type is managed by one of the underlying {@link Metamodel} instances. + * + * @param type must not be {@literal null}. + * @return + */ + public boolean isMetamodelManagedType(Class type) { + return getMetamodelFor(type) != null; } /**