Introduce `VirtualIdEmbeddable` and `IdClassEmbeddable`

Clean-up

Still need to
  - integrate EmbeddableInstantiator work
  - integrate embedded forms.  `VirtualIdEmbeddable` does not really need it as it can use the id-mapping itself as the embedded form.  But `IdClassEmbedded` should really be integrated
  - integrate `VirtualKeyEmbeddable` and `VirtualKeyEmbedded` for use as inverse composite fks
  - share `#finishInit` handling for `EmbeddableMappingType`, `VirtualIdEmbeddable` and `IdClassEmbeddable`
This commit is contained in:
Steve Ebersole 2021-11-22 13:00:36 -06:00
parent 0322d8fa84
commit bb2b0a6c47
3 changed files with 5 additions and 90 deletions

View File

@ -11,7 +11,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.function.BiConsumer;
import org.hibernate.FetchMode;
import org.hibernate.MappingException;
@ -68,7 +67,6 @@ import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.metamodel.mapping.PropertyBasedMapping;
import org.hibernate.metamodel.mapping.SelectableMapping;
import org.hibernate.metamodel.mapping.SelectableMappings;
import org.hibernate.metamodel.mapping.SingularAttributeMapping;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadata;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess;
import org.hibernate.metamodel.model.convert.spi.BasicValueConverter;
@ -149,9 +147,7 @@ public class MappingModelCreationHelper {
EntityPersister entityPersister,
String rootTableName,
String[] rootTableKeyColumnNames,
CompositeType cidType,
PersistentClass bootEntityDescriptor,
BiConsumer<String,SingularAttributeMapping> idSubAttributeConsumer,
MappingModelCreationProcess creationProcess) {
return new NonAggregatedIdentifierMappingImpl(
entityPersister,
@ -160,81 +156,6 @@ public class MappingModelCreationHelper {
rootTableKeyColumnNames,
creationProcess
);
// final Component bootIdClassComponent = (Component) bootEntityDescriptor.getIdentifier();
// final Component bootVirtualComponent;
// if ( bootEntityDescriptor.getIdentifierMapper() == null ) {
// // If there is no id-class, there apparently also is no id mapper
// bootVirtualComponent = bootIdClassComponent;
// }
// else {
// bootVirtualComponent = bootEntityDescriptor.getIdentifierMapper();
// }
//
// final EmbeddableMappingType embeddableMappingType = EmbeddableMappingType.from(
// bootVirtualComponent,
// (CompositeType) bootVirtualComponent.getType(),
// rootTableName,
// rootTableKeyColumnNames,
// attributeMappingType -> {
// final PropertyAccess propertyAccess = PropertyAccessStrategyMapImpl.INSTANCE.buildPropertyAccess(
// null,
// EntityIdentifierMapping.ROLE_LOCAL_NAME
// );
// final StateArrayContributorMetadataAccess attributeMetadataAccess = getStateArrayContributorMetadataAccess(
// propertyAccess
// );
//
// final EmbeddableMappingType idClassType;
// if ( bootIdClassComponent != bootVirtualComponent ) {
// idClassType = EmbeddableMappingType.from(
// bootIdClassComponent,
// (CompositeType) bootIdClassComponent.getType(),
// rootTableName,
// rootTableKeyColumnNames,
// idClassEmbeddableType -> new EmbeddedAttributeMapping(
// "{id-class}",
// entityPersister.getNavigableRole()
// .append( EntityIdentifierMapping.ROLE_LOCAL_NAME )
// .append( "{id-class}" ),
// -1,
// null,
// attributeMetadataAccess,
// (String) null,
// FetchTiming.IMMEDIATE,
// FetchStyle.JOIN,
// idClassEmbeddableType,
// entityPersister,
// propertyAccess,
// null
// ),
// creationProcess
// );
// }
// else {
// idClassType = attributeMappingType;
// }
// return new NonAggregatedIdentifierMappingImpl(
// attributeMappingType,
// entityPersister,
// idClassType,
// attributeMetadataAccess,
// rootTableName,
// creationProcess
// );
// },
// creationProcess
// );
//
// // Inject the model part also in the composite type of the id-class, because that is what we actually "instantiate"
// // which needs the model part for instantiation
//// final CompositeIdentifierMapping compositeIdentifierMapping = (CompositeIdentifierMapping) virtualIdEmbeddable.getEmbeddedValueMapping();
//// ( (CompositeTypeImplementor) virtualIdSource.getType() ).injectMappingModelPart(
//// (EmbeddableValuedModelPart) compositeIdentifierMapping,
//// creationProcess
//// );
//
// return compositeIdentifierMapping;
}
@ -319,6 +240,7 @@ public class MappingModelCreationHelper {
// we want to "decompose" the "type" into its various pieces as expected by the mapping
assert valueConverter.getRelationalJavaDescriptor() == resolution.getRelationalJavaDescriptor();
//noinspection unchecked
final BasicType<?> mappingBasicType = creationProcess.getCreationContext()
.getDomainModel()
.getTypeConfiguration()

View File

@ -5878,7 +5878,7 @@ public abstract class AbstractEntityPersister
}
// otherwise we have a non-encapsulated composite-identifier
return generateNonEncapsulatedCompositeIdentifierMapping( creationProcess, bootEntityDescriptor, cidType );
return generateNonEncapsulatedCompositeIdentifierMapping( creationProcess, bootEntityDescriptor );
}
return new BasicEntityIdentifierMappingImpl(
@ -5894,17 +5894,14 @@ public abstract class AbstractEntityPersister
protected EntityIdentifierMapping generateNonEncapsulatedCompositeIdentifierMapping(
MappingModelCreationProcess creationProcess,
PersistentClass bootEntityDescriptor,
CompositeType cidType) {
PersistentClass bootEntityDescriptor) {
assert declaredAttributeMappings != null;
return MappingModelCreationHelper.buildNonEncapsulatedCompositeIdentifierMapping(
this,
getTableName(),
getRootTableKeyColumnNames(),
cidType,
bootEntityDescriptor,
declaredAttributeMappings::put,
creationProcess
);
}

View File

@ -9,7 +9,6 @@ package org.hibernate.persister.entity;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -1215,7 +1214,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
}
// otherwise we have a non-encapsulated composite-identifier
return generateNonEncapsulatedCompositeIdentifierMapping( creationProcess, bootEntityDescriptor, cidType );
return generateNonEncapsulatedCompositeIdentifierMapping( creationProcess, bootEntityDescriptor );
}
return new BasicEntityIdentifierMappingImpl(
@ -1265,17 +1264,14 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
protected EntityIdentifierMapping generateNonEncapsulatedCompositeIdentifierMapping(
MappingModelCreationProcess creationProcess,
PersistentClass bootEntityDescriptor,
CompositeType cidType) {
PersistentClass bootEntityDescriptor) {
assert declaredAttributeMappings != null;
return MappingModelCreationHelper.buildNonEncapsulatedCompositeIdentifierMapping(
this,
getTableName(),
tableKeyColumns[0],
cidType,
bootEntityDescriptor,
declaredAttributeMappings::put,
creationProcess
);
}