use of org.hibernate.metamodel.mapping.MappingType in project hibernate-orm by hibernate.
the class DefaultLoadEventListener method checkIdClass.
private void checkIdClass(final EntityPersister persister, final LoadEvent event, final LoadType loadType, final Class<?> idClass) {
// we may have the jpa requirement of allowing find-by-id where id is the "simple pk value" of a
// dependent objects parent. This is part of its generally goofy derived identity "feature"
final EntityIdentifierMapping idMapping = persister.getIdentifierMapping();
if (idMapping instanceof CompositeIdentifierMapping) {
final CompositeIdentifierMapping compositeIdMapping = (CompositeIdentifierMapping) idMapping;
final List<AttributeMapping> attributeMappings = compositeIdMapping.getPartMappingType().getAttributeMappings();
if (attributeMappings.size() == 1) {
final AttributeMapping singleIdAttribute = attributeMappings.get(0);
if (singleIdAttribute.getMappedType() instanceof EntityMappingType) {
final EntityMappingType parentIdTargetMapping = (EntityMappingType) singleIdAttribute.getMappedType();
final EntityIdentifierMapping parentIdTargetIdMapping = parentIdTargetMapping.getIdentifierMapping();
final MappingType parentIdType = parentIdTargetIdMapping instanceof CompositeIdentifierMapping ? ((CompositeIdentifierMapping) parentIdTargetIdMapping).getMappedIdEmbeddableTypeDescriptor() : parentIdTargetIdMapping.getMappedType();
if (parentIdType.getMappedJavaType().getJavaTypeClass().isInstance(event.getEntityId())) {
// yep that's what we have...
loadByDerivedIdentitySimplePkValue(event, loadType, persister, compositeIdMapping, (EntityPersister) parentIdTargetMapping);
return;
}
}
} else if (idMapping instanceof NonAggregatedIdentifierMapping) {
if (idClass.isInstance(event.getEntityId())) {
return;
}
}
}
throw new TypeMismatchException("Provided id of the wrong type for class " + persister.getEntityName() + ". Expected: " + idClass + ", got " + event.getEntityId().getClass());
}
use of org.hibernate.metamodel.mapping.MappingType in project hibernate-orm by hibernate.
the class ColumnReference method getTableReference.
TableReference getTableReference(TableGroup tableGroup) {
ModelPartContainer modelPart = tableGroup.getModelPart();
if (modelPart instanceof PluralAttributeMapping) {
final PluralAttributeMapping pluralAttribute = (PluralAttributeMapping) modelPart;
if (!pluralAttribute.getCollectionDescriptor().hasManyToManyOrdering()) {
return tableGroup.getPrimaryTableReference();
}
final MappingType elementMappingType = pluralAttribute.getElementDescriptor().getPartMappingType();
if (elementMappingType instanceof AbstractEntityPersister) {
final AbstractEntityPersister abstractEntityPersister = (AbstractEntityPersister) elementMappingType;
final int tableNumber = abstractEntityPersister.determineTableNumberForColumn(columnExpression);
final String tableName = abstractEntityPersister.getTableName(tableNumber);
return tableGroup.getTableReference(tableGroup.getNavigablePath(), tableName);
} else {
return tableGroup.getPrimaryTableReference();
}
}
return null;
}
Aggregations