use of org.hibernate.metamodel.model.domain.AbstractIdentifiableType in project hibernate-orm by hibernate.
the class MetadataContext method applyIdMetadata.
// 1) create the part
// 2) register the part (mapping role)
// 3) somehow get the mapping role "into" the part (setter, ?)
private void applyIdMetadata(PersistentClass persistentClass, IdentifiableDomainType<?> identifiableType) {
if (persistentClass.hasIdentifierProperty()) {
final Property declaredIdentifierProperty = persistentClass.getDeclaredIdentifierProperty();
if (declaredIdentifierProperty != null) {
final SingularPersistentAttribute<?, Object> idAttribute = attributeFactory.buildIdAttribute(identifiableType, declaredIdentifierProperty);
// noinspection unchecked rawtypes
((AttributeContainer) identifiableType).getInFlightAccess().applyIdAttribute(idAttribute);
}
} else {
if (!(persistentClass.getIdentifier() instanceof Component)) {
throw new MappingException("Expecting Component for id mapping with no id-attribute");
}
// Handle the actual id-attributes
final Component cidValue = (Component) persistentClass.getIdentifier();
final List<Property> cidProperties;
final int propertySpan;
final EmbeddableTypeImpl<?> idClassType;
final Component identifierMapper = persistentClass.getIdentifierMapper();
if (identifierMapper != null) {
cidProperties = identifierMapper.getProperties();
propertySpan = identifierMapper.getPropertySpan();
idClassType = applyIdClassMetadata((Component) persistentClass.getIdentifier());
} else {
cidProperties = cidValue.getProperties();
propertySpan = cidValue.getPropertySpan();
idClassType = null;
}
assert cidValue.isEmbedded();
AbstractIdentifiableType<?> idType = (AbstractIdentifiableType<?>) identifiableTypesByName.get(cidValue.getOwner().getEntityName());
// noinspection rawtypes
Set idAttributes = idType.getIdClassAttributesSafely();
if (idAttributes == null) {
idAttributes = new HashSet<>(propertySpan);
for (Property cidSubproperty : cidProperties) {
final SingularPersistentAttribute<?, Object> cidSubAttr = attributeFactory.buildIdAttribute(idType, cidSubproperty);
// noinspection unchecked
idAttributes.add(cidSubAttr);
}
}
AttributeContainer<?> container = (AttributeContainer<?>) identifiableType;
// noinspection unchecked
container.getInFlightAccess().applyNonAggregatedIdAttributes(idAttributes, idClassType);
}
}
Aggregations