* This method does additional checks to make sure that the target
* entity is indeed an entity class.
*/
@Override
public MetadataDescriptor getReferenceDescriptor() {
MetadataDescriptor referenceDescriptor;
// When processing metamodel mapped superclasses, we don't have the
// luxury of a full type context as we would during regular metadata
// processing (e.g. to figure out generic types). The metamodel mapped
// superclass descriptors must therefore rely on a real child descriptor
// to extract this information and process correctly. When a type is
// unknown, the reference class name currently defaults to java.lang.string.
// @see MetadataAnnotatedElement getRawClass(MetadataDescriptor)
if (getDescriptor().isMappedSuperclass() && getReferenceClassName().equals(MetadataAnnotatedElement.DEFAULT_RAW_CLASS)) {
MappingAccessor childMappingAccessor = getDescriptor().getMetamodelMappedSuperclassChildDescriptor().getMappingAccessor(getAttributeName());
referenceDescriptor = childMappingAccessor.getReferenceDescriptor();
if (referenceDescriptor.isInheritanceSubclass()) {
referenceDescriptor = referenceDescriptor.getInheritanceRootDescriptor();
}
} else {
ClassAccessor accessor = getProject().getAccessor(getReferenceClassName());
referenceDescriptor = (accessor != null) ? accessor.getDescriptor() : null;
if (referenceDescriptor == null) {
MetadataProcessor compositeProcessor = getProject().getCompositeProcessor();
if (compositeProcessor != null) {
for (MetadataProject pearProject : compositeProcessor.getPearProjects(getProject())) {
accessor = pearProject.getAccessor(getReferenceClassName());
if (accessor != null) {
referenceDescriptor = accessor.getDescriptor();
break;
}
}
}
}
}
// Validate the reference descriptor is valid.
if (referenceDescriptor == null || referenceDescriptor.isEmbeddable() || referenceDescriptor.isEmbeddableCollection()) {
throw ValidationException.nonEntityTargetInRelationship(getJavaClass(), getReferenceClass(), getAnnotatedElement());
}
return referenceDescriptor;
}