Search in sources :

Example 1 with EntityInstantiator

use of org.hibernate.metamodel.spi.EntityInstantiator in project hibernate-orm by hibernate.

the class AbstractEntityPersister method prepareMappingModel.

private void prepareMappingModel(MappingModelCreationProcess creationProcess, PersistentClass bootEntityDescriptor) {
    final EntityInstantiator instantiator = getRepresentationStrategy().getInstantiator();
    final Supplier<?> templateInstanceCreator;
    if (!instantiator.canBeInstantiated()) {
        templateInstanceCreator = null;
    } else {
        final LazyValue<?> templateCreator = new LazyValue<>(() -> instantiator.instantiate(creationProcess.getCreationContext().getSessionFactory()));
        templateInstanceCreator = templateCreator::getValue;
    }
    identifierMapping = creationProcess.processSubPart(EntityIdentifierMapping.ROLE_LOCAL_NAME, (role, process) -> generateIdentifierMapping(templateInstanceCreator, bootEntityDescriptor, process));
    versionMapping = generateVersionMapping(templateInstanceCreator, bootEntityDescriptor, creationProcess);
    if (rowIdName == null) {
        rowIdMapping = null;
    } else {
        rowIdMapping = creationProcess.processSubPart(rowIdName, (role, process) -> new EntityRowIdMappingImpl(rowIdName, this.getTableName(), this));
    }
    discriminatorMapping = generateDiscriminatorMapping(bootEntityDescriptor, creationProcess);
}
Also used : Alias(org.hibernate.sql.Alias) Property(org.hibernate.mapping.Property) SqlFragmentPredicate(org.hibernate.persister.internal.SqlFragmentPredicate) BasicType(org.hibernate.type.BasicType) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) ClassMetadata(org.hibernate.metadata.ClassMetadata) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) ReferenceCacheEntryImpl(org.hibernate.cache.spi.entry.ReferenceCacheEntryImpl) MappingModelCreationHelper(org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper) Expectations(org.hibernate.jdbc.Expectations) PostInsertIdentifierGenerator(org.hibernate.id.PostInsertIdentifierGenerator) Map(java.util.Map) EntityVersionMapping(org.hibernate.metamodel.mapping.EntityVersionMapping) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) IdentifierGenerator(org.hibernate.id.IdentifierGenerator) Optimizer(org.hibernate.id.enhanced.Optimizer) SingleIdEntityLoader(org.hibernate.loader.ast.spi.SingleIdEntityLoader) GeneratedValuesProcessor(org.hibernate.metamodel.mapping.internal.GeneratedValuesProcessor) NavigablePath(org.hibernate.query.spi.NavigablePath) LazyAttributeDescriptor(org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeDescriptor) Value(org.hibernate.mapping.Value) PreparedStatement(java.sql.PreparedStatement) SimpleFromClauseAccessImpl(org.hibernate.sql.ast.spi.SimpleFromClauseAccessImpl) Subclass(org.hibernate.mapping.Subclass) SqlAliasBase(org.hibernate.sql.ast.spi.SqlAliasBase) Serializable(java.io.Serializable) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) CacheHelper(org.hibernate.engine.internal.CacheHelper) SelectStatement(org.hibernate.sql.ast.tree.select.SelectStatement) PersisterCreationContext(org.hibernate.persister.spi.PersisterCreationContext) SqmMutationStrategyHelper(org.hibernate.query.sqm.mutation.internal.SqmMutationStrategyHelper) TooManyRowsAffectedException(org.hibernate.jdbc.TooManyRowsAffectedException) Dialect(org.hibernate.dialect.Dialect) CascadeStyle(org.hibernate.engine.spi.CascadeStyle) FetchMode(org.hibernate.FetchMode) UnstructuredCacheEntry(org.hibernate.cache.spi.entry.UnstructuredCacheEntry) CollectionPersister(org.hibernate.persister.collection.CollectionPersister) EnhancementHelper(org.hibernate.bytecode.enhance.spi.interceptor.EnhancementHelper) SelfDirtinessTracker(org.hibernate.engine.spi.SelfDirtinessTracker) EmbeddedAttributeMapping(org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping) SimpleNaturalIdMapping(org.hibernate.metamodel.mapping.internal.SimpleNaturalIdMapping) JdbcEnvironment(org.hibernate.engine.jdbc.env.spi.JdbcEnvironment) AssertionFailure(org.hibernate.AssertionFailure) SingleIdEntityLoaderDynamicBatch(org.hibernate.loader.ast.internal.SingleIdEntityLoaderDynamicBatch) FilterHelper(org.hibernate.internal.FilterHelper) QueryOptions(org.hibernate.query.spi.QueryOptions) Session(org.hibernate.Session) SessionFactoryOptions(org.hibernate.boot.spi.SessionFactoryOptions) EntityDataAccess(org.hibernate.cache.spi.access.EntityDataAccess) Metadata(org.hibernate.boot.Metadata) Supplier(java.util.function.Supplier) NaturalIdResolutions(org.hibernate.engine.spi.NaturalIdResolutions) SemanticException(org.hibernate.query.SemanticException) EntityVersionMappingImpl(org.hibernate.metamodel.mapping.internal.EntityVersionMappingImpl) LinkedHashMap(java.util.LinkedHashMap) NamedTableReference(org.hibernate.sql.ast.tree.from.NamedTableReference) MultiIdLoadOptions(org.hibernate.loader.ast.spi.MultiIdLoadOptions) Preparable(org.hibernate.loader.ast.internal.Preparable) DiscriminatedAssociationAttributeMapping(org.hibernate.metamodel.mapping.internal.DiscriminatedAssociationAttributeMapping) ToOneAttributeMapping(org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping) StandardTableGroup(org.hibernate.sql.ast.tree.from.StandardTableGroup) InFlightEntityMappingType(org.hibernate.metamodel.mapping.internal.InFlightEntityMappingType) LoaderSelectBuilder(org.hibernate.loader.ast.internal.LoaderSelectBuilder) LazyAttributesMetadata(org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributesMetadata) SimpleSelect(org.hibernate.sql.SimpleSelect) EntityDiscriminatorMapping(org.hibernate.metamodel.mapping.EntityDiscriminatorMapping) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) EntityKey(org.hibernate.engine.spi.EntityKey) Table(org.hibernate.mapping.Table) Fetch(org.hibernate.sql.results.graph.Fetch) NaturalIdLoader(org.hibernate.loader.ast.spi.NaturalIdLoader) QueryableCollection(org.hibernate.persister.collection.QueryableCollection) Template(org.hibernate.sql.Template) FromClauseAccess(org.hibernate.sql.ast.spi.FromClauseAccess) TreeMap(java.util.TreeMap) BytecodeLazyAttributeInterceptor(org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor) NaturalIdMapping(org.hibernate.metamodel.mapping.NaturalIdMapping) SqlSelectionImpl(org.hibernate.sql.results.internal.SqlSelectionImpl) CachedNaturalIdValueSource(org.hibernate.engine.spi.CachedNaturalIdValueSource) AssociationType(org.hibernate.type.AssociationType) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) AnyType(org.hibernate.type.AnyType) EntityResultImpl(org.hibernate.sql.results.graph.entity.internal.EntityResultImpl) SingleIdEntityLoaderStandardImpl(org.hibernate.loader.ast.internal.SingleIdEntityLoaderStandardImpl) PersistentCollection(org.hibernate.collection.spi.PersistentCollection) LockModeEnumMap(org.hibernate.internal.util.collections.LockModeEnumMap) Locale(java.util.Locale) Binder(org.hibernate.id.insert.Binder) ComparisonOperator(org.hibernate.query.sqm.ComparisonOperator) LazyPropertyInitializer(org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer) PersistentAttributeInterceptable(org.hibernate.engine.spi.PersistentAttributeInterceptable) Formula(org.hibernate.mapping.Formula) Collection(java.util.Collection) StaleObjectStateException(org.hibernate.StaleObjectStateException) Column(org.hibernate.mapping.Column) StatisticsImplementor(org.hibernate.stat.spi.StatisticsImplementor) BasicBatchKey(org.hibernate.engine.jdbc.batch.internal.BasicBatchKey) Objects(java.util.Objects) ArrayHelper(org.hibernate.internal.util.collections.ArrayHelper) EntityRowIdMappingImpl(org.hibernate.metamodel.mapping.internal.EntityRowIdMappingImpl) Queryable(org.hibernate.metamodel.mapping.Queryable) Update(org.hibernate.sql.Update) LoaderSqlAstCreationState(org.hibernate.loader.ast.internal.LoaderSqlAstCreationState) SelectableConsumer(org.hibernate.metamodel.mapping.SelectableConsumer) IndexedConsumer(org.hibernate.mapping.IndexedConsumer) DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) OptimisticLockStyle(org.hibernate.engine.OptimisticLockStyle) CacheEntityLoaderHelper(org.hibernate.loader.entity.CacheEntityLoaderHelper) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) RootClass(org.hibernate.mapping.RootClass) OptimizableGenerator(org.hibernate.id.OptimizableGenerator) TableReference(org.hibernate.sql.ast.tree.from.TableReference) HashSet(java.util.HashSet) ModelPart(org.hibernate.metamodel.mapping.ModelPart) Loader(org.hibernate.loader.ast.spi.Loader) CompositeType(org.hibernate.type.CompositeType) ManagedMappingType(org.hibernate.metamodel.mapping.ManagedMappingType) LockingStrategy(org.hibernate.dialect.lock.LockingStrategy) DiscriminatedAssociationModelPart(org.hibernate.metamodel.mapping.DiscriminatedAssociationModelPart) SqlAliasBaseManager(org.hibernate.sql.ast.spi.SqlAliasBaseManager) InsertGeneratedIdentifierDelegate(org.hibernate.id.insert.InsertGeneratedIdentifierDelegate) EntityEntryFactory(org.hibernate.engine.spi.EntityEntryFactory) SqmFunctionRegistry(org.hibernate.query.sqm.function.SqmFunctionRegistry) EntityMetamodel(org.hibernate.tuple.entity.EntityMetamodel) MappingModelCreationProcess(org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess) Consumer(java.util.function.Consumer) EntityRepresentationStrategy(org.hibernate.metamodel.spi.EntityRepresentationStrategy) JdbcParameter(org.hibernate.sql.ast.tree.expression.JdbcParameter) SelectableMapping(org.hibernate.metamodel.mapping.SelectableMapping) Selectable(org.hibernate.mapping.Selectable) NonAggregatedIdentifierMapping(org.hibernate.metamodel.mapping.NonAggregatedIdentifierMapping) EntityEntry(org.hibernate.engine.spi.EntityEntry) BitSet(java.util.BitSet) Comparator(java.util.Comparator) MutableEntityEntryFactory(org.hibernate.engine.internal.MutableEntityEntryFactory) MultiIdLoaderStandard(org.hibernate.loader.ast.internal.MultiIdLoaderStandard) Arrays(java.util.Arrays) EventSource(org.hibernate.event.spi.EventSource) ReflectionOptimizer(org.hibernate.bytecode.spi.ReflectionOptimizer) PersistenceContext(org.hibernate.engine.spi.PersistenceContext) PropertyAccess(org.hibernate.property.access.spi.PropertyAccess) SingleUniqueKeyEntityLoaderStandard(org.hibernate.loader.ast.internal.SingleUniqueKeyEntityLoaderStandard) ForeignKeyDescriptor(org.hibernate.metamodel.mapping.ForeignKeyDescriptor) PersistentClass(org.hibernate.mapping.PersistentClass) ResultSet(java.sql.ResultSet) MultiIdEntityLoader(org.hibernate.loader.ast.spi.MultiIdEntityLoader) LazyAttributeLoadingInterceptor(org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor) Insert(org.hibernate.sql.Insert) StaleStateException(org.hibernate.StaleStateException) SingleUniqueKeyEntityLoader(org.hibernate.loader.ast.spi.SingleUniqueKeyEntityLoader) BytecodeEnhancementMetadata(org.hibernate.bytecode.spi.BytecodeEnhancementMetadata) Fetchable(org.hibernate.sql.results.graph.Fetchable) StructuredCacheEntry(org.hibernate.cache.spi.entry.StructuredCacheEntry) LockOptions(org.hibernate.LockOptions) ImmutableEntityEntryFactory(org.hibernate.engine.internal.ImmutableEntityEntryFactory) StringHelper(org.hibernate.internal.util.StringHelper) Set(java.util.Set) Expression(org.hibernate.sql.ast.tree.expression.Expression) SingleIdArrayLoadPlan(org.hibernate.loader.ast.internal.SingleIdArrayLoadPlan) Assigned(org.hibernate.id.Assigned) LazyValue(org.hibernate.internal.util.LazyValue) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) BasicEntityIdentifierMappingImpl(org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl) Expectation(org.hibernate.jdbc.Expectation) RuntimeModelCreationContext(org.hibernate.metamodel.spi.RuntimeModelCreationContext) EnhancementAsProxyLazinessInterceptor(org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor) HibernateException(org.hibernate.HibernateException) CacheEntryStructure(org.hibernate.cache.spi.entry.CacheEntryStructure) QueryException(org.hibernate.QueryException) StateArrayContributorMapping(org.hibernate.metamodel.mapping.StateArrayContributorMapping) MutabilityPlan(org.hibernate.type.descriptor.java.MutabilityPlan) JavaType(org.hibernate.type.descriptor.java.JavaType) Setter(org.hibernate.property.access.spi.Setter) Clause(org.hibernate.sql.ast.Clause) ArrayList(java.util.ArrayList) StandardCacheEntryImpl(org.hibernate.cache.spi.entry.StandardCacheEntryImpl) ValueGeneration(org.hibernate.tuple.ValueGeneration) SQLException(java.sql.SQLException) BiConsumer(java.util.function.BiConsumer) PostInsertIdentityPersister(org.hibernate.id.PostInsertIdentityPersister) FetchTiming(org.hibernate.engine.FetchTiming) BulkInsertionCapableIdentifierGenerator(org.hibernate.id.BulkInsertionCapableIdentifierGenerator) SingularAttributeMapping(org.hibernate.metamodel.mapping.SingularAttributeMapping) Delete(org.hibernate.sql.Delete) StatefulPersistenceContext(org.hibernate.engine.internal.StatefulPersistenceContext) CompoundNaturalIdMapping(org.hibernate.metamodel.mapping.internal.CompoundNaturalIdMapping) LoadEvent(org.hibernate.event.spi.LoadEvent) MultiNaturalIdLoader(org.hibernate.loader.ast.spi.MultiNaturalIdLoader) CollectionHelper(org.hibernate.internal.util.collections.CollectionHelper) NamedQueryMemento(org.hibernate.query.named.NamedQueryMemento) SqmMultiTableMutationStrategy(org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy) Filter(org.hibernate.Filter) SQLQueryParser(org.hibernate.query.sql.internal.SQLQueryParser) Lifecycle(org.hibernate.classic.Lifecycle) MessageHelper(org.hibernate.pretty.MessageHelper) Any(org.hibernate.mapping.Any) EntityBasedAssociationAttribute(org.hibernate.tuple.entity.EntityBasedAssociationAttribute) MappingModelHelper(org.hibernate.metamodel.mapping.MappingModelHelper) SqlAstCreationContext(org.hibernate.sql.ast.spi.SqlAstCreationContext) NonIdentifierAttribute(org.hibernate.tuple.NonIdentifierAttribute) ComparisonPredicate(org.hibernate.sql.ast.tree.predicate.ComparisonPredicate) JDBCException(org.hibernate.JDBCException) PersistentAttributeInterceptor(org.hibernate.engine.spi.PersistentAttributeInterceptor) ExecuteUpdateResultCheckStyle(org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle) TableReferenceJoin(org.hibernate.sql.ast.tree.from.TableReferenceJoin) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) CacheEntry(org.hibernate.cache.spi.entry.CacheEntry) AttributeMetadataAccess(org.hibernate.metamodel.mapping.AttributeMetadataAccess) IdentityHashMap(java.util.IdentityHashMap) DependantValue(org.hibernate.mapping.DependantValue) VirtualModelPart(org.hibernate.metamodel.mapping.VirtualModelPart) DomainResult(org.hibernate.sql.results.graph.DomainResult) SqmMultiTableInsertStrategy(org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy) NavigableRole(org.hibernate.metamodel.model.domain.NavigableRole) LoadQueryInfluencers(org.hibernate.engine.spi.LoadQueryInfluencers) List(java.util.List) EntityInstantiator(org.hibernate.metamodel.spi.EntityInstantiator) SingleIdEntityLoaderProvidedQueryImpl(org.hibernate.loader.ast.internal.SingleIdEntityLoaderProvidedQueryImpl) MappingException(org.hibernate.MappingException) BasicValue(org.hibernate.mapping.BasicValue) SessionImplementor(org.hibernate.engine.spi.SessionImplementor) QuerySpec(org.hibernate.sql.ast.tree.select.QuerySpec) SortedMap(java.util.SortedMap) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) BasicValuedModelPart(org.hibernate.metamodel.mapping.BasicValuedModelPart) CoreMessageLogger(org.hibernate.internal.CoreMessageLogger) Junction(org.hibernate.sql.ast.tree.predicate.Junction) InDatabaseValueGenerationStrategy(org.hibernate.tuple.InDatabaseValueGenerationStrategy) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) CollectionType(org.hibernate.type.CollectionType) HashMap(java.util.HashMap) SqlAliasStemHelper(org.hibernate.sql.ast.spi.SqlAliasStemHelper) InMemoryValueGenerationStrategy(org.hibernate.tuple.InMemoryValueGenerationStrategy) EntityType(org.hibernate.type.EntityType) RepresentationMode(org.hibernate.metamodel.RepresentationMode) FilterAliasGenerator(org.hibernate.internal.FilterAliasGenerator) AttributeMetadata(org.hibernate.metamodel.mapping.AttributeMetadata) SqlAliasBaseConstant(org.hibernate.sql.ast.spi.SqlAliasBaseConstant) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) LockMode(org.hibernate.LockMode) Predicate(org.hibernate.sql.ast.tree.predicate.Predicate) Versioning(org.hibernate.engine.internal.Versioning) AliasedExpression(org.hibernate.sql.ast.tree.expression.AliasedExpression) ExplicitColumnDiscriminatorMappingImpl(org.hibernate.metamodel.mapping.internal.ExplicitColumnDiscriminatorMappingImpl) SelectClause(org.hibernate.sql.ast.tree.select.SelectClause) Association(org.hibernate.metamodel.mapping.Association) EntityRowIdMapping(org.hibernate.metamodel.mapping.EntityRowIdMapping) GenerationTiming(org.hibernate.tuple.GenerationTiming) Component(org.hibernate.mapping.Component) CollectionKey(org.hibernate.engine.spi.CollectionKey) StateArrayContributorMetadata(org.hibernate.metamodel.mapping.StateArrayContributorMetadata) LazyInitializationException(org.hibernate.LazyInitializationException) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) NaturalIdDataAccess(org.hibernate.cache.spi.access.NaturalIdDataAccess) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping) Collections(java.util.Collections) CoreLogging(org.hibernate.internal.CoreLogging) Type(org.hibernate.type.Type) LazyValue(org.hibernate.internal.util.LazyValue) EntityRowIdMappingImpl(org.hibernate.metamodel.mapping.internal.EntityRowIdMappingImpl) EntityInstantiator(org.hibernate.metamodel.spi.EntityInstantiator)

Aggregations

Serializable (java.io.Serializable)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 BitSet (java.util.BitSet)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 IdentityHashMap (java.util.IdentityHashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 SortedMap (java.util.SortedMap)1