DATAJPA-1560 - Avoid unnecessary creation of exceptions when checking if a type is managed.

We check a type is managed before trying to access its `ManagedType`.

Original pull request: #384.
This commit is contained in:
Jens Schauder
2019-06-18 08:49:35 +02:00
committed by Mark Paluch
parent e7b4233e25
commit 7b3f250aeb

View File

@@ -412,13 +412,17 @@ public class JpaMetamodelEntityInformation<T, ID> extends JpaEntityInformationSu
return false;
}
try {
ManagedType<?> managedType = this.metamodel.managedType(ProxyUtils.getUserClass(value));
return managedType != null && managedType.getPersistenceType() == PersistenceType.ENTITY;
} catch (IllegalArgumentException iae) {
// no mapped type
Class<?> userClass = ProxyUtils.getUserClass(value);
if (!this.jpaMetamodel.isJpaManaged(userClass)) {
return false;
}
ManagedType<?> managedType = this.metamodel.managedType(userClass);
Assert.state(managedType != null, "ManagedType must not be null. We checked that it exists before.");
return managedType.getPersistenceType() == PersistenceType.ENTITY;
}
}
}