HHH-15393 - Improve write-paths to use mapping model

This commit is contained in:
Steve Ebersole 2022-11-29 16:00:53 -06:00
parent 3e6fcdeda3
commit 815c4eb4a1
16 changed files with 151 additions and 112 deletions

View File

@ -28,8 +28,8 @@ import org.hibernate.engine.spi.SelfDirtinessTracker;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.Status; import org.hibernate.engine.spi.Status;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.UniqueKeyLoadable;
import org.hibernate.pretty.MessageHelper; import org.hibernate.pretty.MessageHelper;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
@ -311,7 +311,8 @@ public abstract class AbstractEntityEntry implements Serializable, EntityEntry {
return null; return null;
} }
else { else {
final int propertyIndex = ( (UniqueKeyLoadable) persister ).getPropertyIndex( propertyName ); final AttributeMapping attributeMapping = persister.findAttributeMapping( propertyName );
final int propertyIndex = attributeMapping.getStateArrayPosition();
return loadedState[propertyIndex]; return loadedState[propertyIndex];
} }
} }
@ -323,7 +324,7 @@ public abstract class AbstractEntityEntry implements Serializable, EntityEntry {
assert propertyName != null; assert propertyName != null;
assert loadedState != null; assert loadedState != null;
final int propertyIndex = ( (UniqueKeyLoadable) persister ).getPropertyIndex( propertyName ); final int propertyIndex = persister.findAttributeMapping( propertyName ).getStateArrayPosition();
loadedState[propertyIndex] = collection; loadedState[propertyIndex] = collection;
} }
} }

View File

@ -10,7 +10,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.Member; import java.lang.reflect.Member;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
import java.util.Iterator;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.PropertyNotFoundException; import org.hibernate.PropertyNotFoundException;
@ -25,11 +24,14 @@ import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.mapping.Value; import org.hibernate.mapping.Value;
import org.hibernate.metamodel.AttributeClassification; import org.hibernate.metamodel.AttributeClassification;
import org.hibernate.metamodel.UnsupportedMappingException;
import org.hibernate.metamodel.RepresentationMode; import org.hibernate.metamodel.RepresentationMode;
import org.hibernate.metamodel.UnsupportedMappingException;
import org.hibernate.metamodel.mapping.AttributeMapping; import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.CompositeIdentifierMapping;
import org.hibernate.metamodel.mapping.EmbeddableMappingType; import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
import org.hibernate.metamodel.mapping.EntityVersionMapping;
import org.hibernate.metamodel.model.domain.AbstractIdentifiableType; import org.hibernate.metamodel.model.domain.AbstractIdentifiableType;
import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.metamodel.model.domain.DomainType;
import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
@ -49,10 +51,7 @@ import org.hibernate.metamodel.spi.EmbeddableRepresentationStrategy;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.property.access.internal.PropertyAccessMapImpl; import org.hibernate.property.access.internal.PropertyAccessMapImpl;
import org.hibernate.property.access.spi.Getter; import org.hibernate.property.access.spi.Getter;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.type.AnyType; import org.hibernate.type.AnyType;
import org.hibernate.type.BasicType;
import org.hibernate.type.EmbeddedComponentType;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry; import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry;
@ -306,36 +305,19 @@ public class AttributeFactory {
private static EntityPersister getDeclaringEntity( private static EntityPersister getDeclaringEntity(
AbstractIdentifiableType<?> ownerType, AbstractIdentifiableType<?> ownerType,
MetadataContext metadataContext) { MetadataContext metadataContext) {
final Type.PersistenceType persistenceType = ownerType.getPersistenceType(); return getDeclarerEntityPersister( ownerType, metadataContext );
if ( persistenceType == Type.PersistenceType.ENTITY ) {
return metadataContext.getMetamodel()
.getEntityDescriptor( ownerType.getTypeName() );
}
else if ( persistenceType == Type.PersistenceType.MAPPED_SUPERCLASS ) {
PersistentClass persistentClass =
metadataContext.getPersistentClassHostingProperties( (MappedSuperclassTypeImpl<?>) ownerType );
return metadataContext.getMetamodel()
.findEntityDescriptor( persistentClass.getClassName() );
}
else {
throw new AssertionFailure( "Cannot get the metamodel for PersistenceType: " + persistenceType );
}
} }
private static EntityMetamodel getDeclarerEntityMetamodel(
private static EntityPersister getDeclarerEntityPersister(
AbstractIdentifiableType<?> ownerType, AbstractIdentifiableType<?> ownerType,
MetadataContext metadataContext) { MetadataContext metadataContext) {
final Type.PersistenceType persistenceType = ownerType.getPersistenceType(); final Type.PersistenceType persistenceType = ownerType.getPersistenceType();
if ( persistenceType == Type.PersistenceType.ENTITY ) { if ( persistenceType == Type.PersistenceType.ENTITY ) {
return metadataContext.getMetamodel() return metadataContext.getMetamodel().getEntityDescriptor( ownerType.getTypeName() );
.getEntityDescriptor( ownerType.getTypeName() )
.getEntityMetamodel();
} }
else if ( persistenceType == Type.PersistenceType.MAPPED_SUPERCLASS ) { else if ( persistenceType == Type.PersistenceType.MAPPED_SUPERCLASS ) {
PersistentClass persistentClass = PersistentClass persistentClass = metadataContext.getPersistentClassHostingProperties( (MappedSuperclassTypeImpl<?>) ownerType );
metadataContext.getPersistentClassHostingProperties( (MappedSuperclassTypeImpl<?>) ownerType ); return metadataContext.getMetamodel().findEntityDescriptor( persistentClass.getClassName() );
return metadataContext.getMetamodel()
.findEntityDescriptor( persistentClass.getClassName() )
.getEntityMetamodel();
} }
else { else {
throw new AssertionFailure( "Cannot get the metamodel for PersistenceType: " + persistenceType ); throw new AssertionFailure( "Cannot get the metamodel for PersistenceType: " + persistenceType );
@ -617,21 +599,16 @@ public class AttributeFactory {
private static final MemberResolver virtualIdentifierMemberResolver = (attributeContext, metadataContext) -> { private static final MemberResolver virtualIdentifierMemberResolver = (attributeContext, metadataContext) -> {
final AbstractIdentifiableType<?> identifiableType = (AbstractIdentifiableType<?>) attributeContext.getOwnerType(); final AbstractIdentifiableType<?> identifiableType = (AbstractIdentifiableType<?>) attributeContext.getOwnerType();
final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( identifiableType, metadataContext ); final EntityPersister entityPersister = getDeclarerEntityPersister( identifiableType, metadataContext );
if ( !entityMetamodel.getIdentifierProperty().isVirtual() ) { final EntityIdentifierMapping identifierMapping = entityPersister.getIdentifierMapping();
throw new IllegalArgumentException( "expecting IdClass mapping" );
} if ( identifierMapping.getNature() != EntityIdentifierMapping.Nature.VIRTUAL ) {
org.hibernate.type.Type type = entityMetamodel.getIdentifierProperty().getType();
if ( !(type instanceof EmbeddedComponentType) ) {
throw new IllegalArgumentException( "expecting IdClass mapping" ); throw new IllegalArgumentException( "expecting IdClass mapping" );
} }
final CompositeIdentifierMapping cid = (CompositeIdentifierMapping) identifierMapping;
final EmbeddableMappingType embeddable = cid.getPartMappingType();
final String attributeName = attributeContext.getPropertyMapping().getName(); final String attributeName = attributeContext.getPropertyMapping().getName();
final EmbeddedComponentType componentType = (EmbeddedComponentType) type;
final EmbeddableValuedModelPart embeddedPart = ( (CompositeTypeImplementor) componentType ).getMappingModelPart();
assert embeddedPart != null;
final EmbeddableMappingType embeddable = embeddedPart.getEmbeddableTypeDescriptor();
final AttributeMapping attributeMapping = embeddable.findAttributeMapping( attributeName ); final AttributeMapping attributeMapping = embeddable.findAttributeMapping( attributeName );
if ( attributeMapping == null ) { if ( attributeMapping == null ) {
throw new PropertyNotFoundException( throw new PropertyNotFoundException(
@ -658,16 +635,16 @@ public class AttributeFactory {
else if ( Type.PersistenceType.ENTITY == persistenceType else if ( Type.PersistenceType.ENTITY == persistenceType
|| Type.PersistenceType.MAPPED_SUPERCLASS == persistenceType ) { || Type.PersistenceType.MAPPED_SUPERCLASS == persistenceType ) {
final AbstractIdentifiableType<?> identifiableType = (AbstractIdentifiableType<?>) ownerType; final AbstractIdentifiableType<?> identifiableType = (AbstractIdentifiableType<?>) ownerType;
final EntityPersister declaringEntityMapping = getDeclaringEntity( identifiableType, metadataContext ); final EntityPersister declaringEntityPersister = getDeclaringEntity( identifiableType, metadataContext );
final EntityMetamodel entityMetamodel = declaringEntityMapping.getEntityMetamodel();
final String propertyName = property.getName(); final String propertyName = property.getName();
final Integer index = entityMetamodel.getPropertyIndexOrNull( propertyName );
if ( index == null ) { final AttributeMapping attributeMapping = declaringEntityPersister.findAttributeMapping( propertyName );
if ( attributeMapping == null ) {
// just like in #determineIdentifierJavaMember , this *should* indicate we have an IdClass mapping // just like in #determineIdentifierJavaMember , this *should* indicate we have an IdClass mapping
return virtualIdentifierMemberResolver.resolveMember( attributeContext, metadataContext ); return virtualIdentifierMemberResolver.resolveMember( attributeContext, metadataContext );
} }
else { else {
final Getter getter = declaringEntityMapping.getRepresentationStrategy().resolvePropertyAccess( property ).getGetter(); final Getter getter = declaringEntityPersister.getRepresentationStrategy().resolvePropertyAccess( property ).getGetter();
return getter instanceof PropertyAccessMapImpl.GetterImpl return getter instanceof PropertyAccessMapImpl.GetterImpl
? new MapMember( propertyName, property.getType().getReturnedClass() ) ? new MapMember( propertyName, property.getType().getReturnedClass() )
: getter.getMember(); : getter.getMember();
@ -681,20 +658,16 @@ public class AttributeFactory {
private final MemberResolver identifierMemberResolver = (attributeContext, metadataContext) -> { private final MemberResolver identifierMemberResolver = (attributeContext, metadataContext) -> {
final AbstractIdentifiableType<?> identifiableType = (AbstractIdentifiableType<?>) attributeContext.getOwnerType(); final AbstractIdentifiableType<?> identifiableType = (AbstractIdentifiableType<?>) attributeContext.getOwnerType();
final EntityPersister declaringEntityMapping = getDeclaringEntity( identifiableType, metadataContext ); final EntityPersister declaringEntityMapping = getDeclaringEntity( identifiableType, metadataContext );
final EntityMetamodel entityMetamodel = declaringEntityMapping.getEntityMetamodel(); final EntityIdentifierMapping identifierMapping = declaringEntityMapping.getIdentifierMapping();
final String attributeName = attributeContext.getPropertyMapping().getName();
if ( !attributeContext.getPropertyMapping().getName() if ( !attributeName.equals( identifierMapping.getAttributeName() ) ) {
.equals( entityMetamodel.getIdentifierProperty().getName() ) ) {
// this *should* indicate processing part of an IdClass... // this *should* indicate processing part of an IdClass...
return virtualIdentifierMemberResolver.resolveMember( attributeContext, metadataContext ); return virtualIdentifierMemberResolver.resolveMember( attributeContext, metadataContext );
} }
final Getter getter = declaringEntityMapping.getRepresentationStrategy().resolvePropertyAccess( attributeContext.getPropertyMapping() ).getGetter(); final Getter getter = declaringEntityMapping.getRepresentationStrategy().resolvePropertyAccess( attributeContext.getPropertyMapping() ).getGetter();
if ( getter instanceof PropertyAccessMapImpl.GetterImpl ) { if ( getter instanceof PropertyAccessMapImpl.GetterImpl ) {
return new MapMember( return new MapMember( identifierMapping.getAttributeName(), identifierMapping.getJavaType().getJavaTypeClass() );
entityMetamodel.getIdentifierProperty().getName(),
entityMetamodel.getIdentifierProperty().getType().getReturnedClass()
);
} }
else { else {
return getter.getMember(); return getter.getMember();
@ -703,20 +676,20 @@ public class AttributeFactory {
private final MemberResolver versionMemberResolver = (attributeContext, metadataContext) -> { private final MemberResolver versionMemberResolver = (attributeContext, metadataContext) -> {
final AbstractIdentifiableType<?> identifiableType = (AbstractIdentifiableType<?>) attributeContext.getOwnerType(); final AbstractIdentifiableType<?> identifiableType = (AbstractIdentifiableType<?>) attributeContext.getOwnerType();
final EntityPersister declaringEntityMapping = getDeclaringEntity( identifiableType, metadataContext ); final EntityPersister entityPersister = getDeclaringEntity( identifiableType, metadataContext );
final EntityMetamodel entityMetamodel = declaringEntityMapping.getEntityMetamodel(); final EntityVersionMapping versionMapping = entityPersister.getVersionMapping();
assert entityPersister.isVersioned();
assert versionMapping != null;
final String versionPropertyName = attributeContext.getPropertyMapping().getName(); final String versionPropertyName = attributeContext.getPropertyMapping().getName();
if ( !versionPropertyName.equals( entityMetamodel.getVersionProperty().getName() ) ) { if ( !versionPropertyName.equals( versionMapping.getVersionAttribute().getAttributeName() ) ) {
// this should never happen, but to be safe... // this should never happen, but to be safe...
throw new IllegalArgumentException( "Given property did not match declared version property" ); throw new IllegalArgumentException( "Given property did not match declared version property" );
} }
final Getter getter = declaringEntityMapping.getRepresentationStrategy().resolvePropertyAccess( attributeContext.getPropertyMapping() ).getGetter(); final Getter getter = entityPersister.getRepresentationStrategy().resolvePropertyAccess( attributeContext.getPropertyMapping() ).getGetter();
if ( getter instanceof PropertyAccessMapImpl.GetterImpl ) { if ( getter instanceof PropertyAccessMapImpl.GetterImpl ) {
return new MapMember( return new MapMember( versionPropertyName, versionMapping.getJavaType().getJavaTypeClass() );
versionPropertyName,
attributeContext.getPropertyMapping().getType().getReturnedClass()
);
} }
else { else {
return getter.getMember(); return getter.getMember();

View File

@ -19,6 +19,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
* @see jakarta.persistence.EmbeddedId * @see jakarta.persistence.EmbeddedId
*/ */
public interface EntityIdentifierMapping extends ValueMapping, ModelPart { public interface EntityIdentifierMapping extends ValueMapping, ModelPart {
String ROLE_LOCAL_NAME = "{id}"; String ROLE_LOCAL_NAME = "{id}";
@Override @Override
@ -26,6 +27,16 @@ public interface EntityIdentifierMapping extends ValueMapping, ModelPart {
return ROLE_LOCAL_NAME; return ROLE_LOCAL_NAME;
} }
/**
* @see Nature
*/
Nature getNature();
/**
* The name of the attribute defining the id, if one
*/
String getAttributeName();
/** /**
* The strategy for distinguishing between detached and transient * The strategy for distinguishing between detached and transient
* state based on the identifier mapping * state based on the identifier mapping
@ -89,4 +100,22 @@ public interface EntityIdentifierMapping extends ValueMapping, ModelPart {
void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session); void setIdentifier(Object entity, Object id, SharedSessionContractImplementor session);
Object instantiate(); Object instantiate();
enum Nature {
/**
* Single column id
*/
SIMPLE,
/**
* @see jakarta.persistence.EmbeddedId
*/
COMPOSITE,
/**
* Composite identifier defined with multiple {@link jakarta.persistence.Id}
* mappings. Often used in conjunction with an {@link jakarta.persistence.IdClass}
*/
VIRTUAL
}
} }

View File

@ -132,6 +132,11 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa
return attributeName; return attributeName;
} }
@Override
public Nature getNature() {
return Nature.SIMPLE;
}
@Override @Override
public IdentifierValue getUnsavedStrategy() { public IdentifierValue getUnsavedStrategy() {
return unsavedStrategy; return unsavedStrategy;

View File

@ -10,8 +10,8 @@ import java.util.function.BiConsumer;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.metamodel.internal.AbstractCompositeIdentifierMapping; import org.hibernate.metamodel.internal.AbstractCompositeIdentifierMapping;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.EmbeddableMappingType; import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.property.access.spi.PropertyAccess; import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
@ -53,6 +53,11 @@ public class EmbeddedIdentifierMappingImpl
return name; return name;
} }
@Override
public Nature getNature() {
return Nature.COMPOSITE;
}
@Override @Override
public EmbeddableMappingType getPartMappingType() { public EmbeddableMappingType getPartMappingType() {
return embeddableDescriptor; return embeddableDescriptor;

View File

@ -92,6 +92,11 @@ public class InverseNonAggregatedIdentifierMapping extends EmbeddedAttributeMapp
return super.getPartName(); return super.getPartName();
} }
@Override
public Nature getNature() {
return Nature.VIRTUAL;
}
@Override @Override
public EmbeddableMappingType getPartMappingType() { public EmbeddableMappingType getPartMappingType() {
return (EmbeddableMappingType) super.getPartMappingType(); return (EmbeddableMappingType) super.getPartMappingType();

View File

@ -200,6 +200,16 @@ public class NonAggregatedIdentifierMappingImpl extends AbstractCompositeIdentif
return super.toSqlExpression( tableGroup, clause, walker, sqlAstCreationState ); return super.toSqlExpression( tableGroup, clause, walker, sqlAstCreationState );
} }
@Override
public Nature getNature() {
return Nature.VIRTUAL;
}
@Override
public String getAttributeName() {
return null;
}
@Override @Override
public Object getIdentifier(Object entity, SharedSessionContractImplementor session) { public Object getIdentifier(Object entity, SharedSessionContractImplementor session) {
return getIdentifier( entity ); return getIdentifier( entity );

View File

@ -33,6 +33,11 @@ public class AnonymousTupleBasicEntityIdentifierMapping
this.delegate = delegate; this.delegate = delegate;
} }
@Override
public Nature getNature() {
return Nature.SIMPLE;
}
@Override @Override
public IdentifierValue getUnsavedStrategy() { public IdentifierValue getUnsavedStrategy() {
return delegate.getUnsavedStrategy(); return delegate.getUnsavedStrategy();

View File

@ -11,17 +11,14 @@ import java.util.Map;
import org.hibernate.Incubating; import org.hibernate.Incubating;
import org.hibernate.engine.spi.IdentifierValue; import org.hibernate.engine.spi.IdentifierValue;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping;
import org.hibernate.metamodel.mapping.CompositeIdentifierMapping; import org.hibernate.metamodel.mapping.CompositeIdentifierMapping;
import org.hibernate.metamodel.mapping.EmbeddableMappingType; import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.MappingType; import org.hibernate.metamodel.mapping.MappingType;
import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.internal.SingleAttributeIdentifierMapping; import org.hibernate.metamodel.mapping.internal.SingleAttributeIdentifierMapping;
import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.metamodel.model.domain.DomainType;
import org.hibernate.property.access.spi.PropertyAccess; import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.query.sqm.SqmExpressible;
/** /**
* @author Christian Beikov * @author Christian Beikov
@ -46,6 +43,11 @@ public class AnonymousTupleEmbeddedEntityIdentifierMapping extends AnonymousTupl
this.delegate = delegate; this.delegate = delegate;
} }
@Override
public Nature getNature() {
return delegate.getNature();
}
@Override @Override
public IdentifierValue getUnsavedStrategy() { public IdentifierValue getUnsavedStrategy() {
return delegate.getUnsavedStrategy(); return delegate.getUnsavedStrategy();

View File

@ -13,17 +13,13 @@ import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming; import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.spi.IdentifierValue; import org.hibernate.engine.spi.IdentifierValue;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.metamodel.mapping.CompositeIdentifierMapping;
import org.hibernate.metamodel.mapping.EmbeddableMappingType; import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.MappingType; import org.hibernate.metamodel.mapping.MappingType;
import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.NonAggregatedIdentifierMapping; import org.hibernate.metamodel.mapping.NonAggregatedIdentifierMapping;
import org.hibernate.metamodel.mapping.internal.IdClassEmbeddable; import org.hibernate.metamodel.mapping.internal.IdClassEmbeddable;
import org.hibernate.metamodel.mapping.internal.SingleAttributeIdentifierMapping;
import org.hibernate.metamodel.mapping.internal.VirtualIdEmbeddable; import org.hibernate.metamodel.mapping.internal.VirtualIdEmbeddable;
import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.metamodel.model.domain.DomainType;
import org.hibernate.property.access.spi.PropertyAccess;
/** /**
* @author Christian Beikov * @author Christian Beikov
@ -48,6 +44,16 @@ public class AnonymousTupleNonAggregatedEntityIdentifierMapping extends Anonymou
this.delegate = delegate; this.delegate = delegate;
} }
@Override
public Nature getNature() {
return Nature.VIRTUAL;
}
@Override
public String getAttributeName() {
return null;
}
@Override @Override
public IdentifierValue getUnsavedStrategy() { public IdentifierValue getUnsavedStrategy() {
return delegate.getUnsavedStrategy(); return delegate.getUnsavedStrategy();

View File

@ -41,7 +41,6 @@ import org.hibernate.metamodel.mapping.EntityVersionMapping;
import org.hibernate.metamodel.mapping.ManagedMappingType; import org.hibernate.metamodel.mapping.ManagedMappingType;
import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.UniqueKeyLoadable;
import org.hibernate.property.access.internal.PropertyAccessStrategyBackRefImpl; import org.hibernate.property.access.internal.PropertyAccessStrategyBackRefImpl;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer; import org.hibernate.proxy.LazyInitializer;
@ -62,9 +61,9 @@ import org.hibernate.type.AssociationType;
import org.hibernate.type.BasicType; import org.hibernate.type.BasicType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import static org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer.UNFETCHED_PROPERTY;
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable; import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable; import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
import static org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer.UNFETCHED_PROPERTY;
import static org.hibernate.internal.log.LoggingHelper.toLoggableString; import static org.hibernate.internal.log.LoggingHelper.toLoggableString;
/** /**
@ -734,7 +733,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
final AssociationType associationType = (AssociationType) propertyType; final AssociationType associationType = (AssociationType) propertyType;
final String ukName = associationType.getLHSPropertyName(); final String ukName = associationType.getLHSPropertyName();
if ( ukName != null ) { if ( ukName != null ) {
final int index = ( (UniqueKeyLoadable) concreteDescriptor ).getPropertyIndex( ukName ); final int index = concreteDescriptor.findAttributeMapping( ukName ).getStateArrayPosition();
final Type type = concreteDescriptor.getPropertyTypes()[index]; final Type type = concreteDescriptor.getPropertyTypes()[index];
// polymorphism not really handled completely correctly, // polymorphism not really handled completely correctly,

View File

@ -130,7 +130,7 @@ public abstract class AbstractBatchEntitySelectFetchInitializer extends Abstract
} }
protected static int getPropertyIndex(EntityInitializer entityInitializer, String propertyName) { protected static int getPropertyIndex(EntityInitializer entityInitializer, String propertyName) {
return entityInitializer.getConcreteDescriptor().getPropertyIndex( propertyName ); return entityInitializer.getConcreteDescriptor().findAttributeMapping( propertyName ).getStateArrayPosition();
} }
@Override @Override

View File

@ -66,7 +66,7 @@ import static org.hibernate.internal.CoreLogging.messageLogger;
public class EntityMetamodel implements Serializable { public class EntityMetamodel implements Serializable {
private static final CoreMessageLogger LOG = messageLogger( EntityMetamodel.class ); private static final CoreMessageLogger LOG = messageLogger( EntityMetamodel.class );
private static final int NO_VERSION_INDX = -66; public static final int NO_VERSION_INDX = -66;
private final SessionFactoryImplementor sessionFactory; private final SessionFactoryImplementor sessionFactory;

View File

@ -8,25 +8,25 @@ package org.hibernate.orm.test.fetchstrategyhelper;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import org.junit.Test;
import org.hibernate.annotations.BatchSize; import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Fetch; import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.FetchMode;
import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming; import org.hibernate.engine.FetchTiming;
import org.hibernate.persister.entity.OuterJoinLoadable;
import org.hibernate.persister.entity.UniqueKeyLoadable;
import org.hibernate.metamodel.mapping.internal.FetchOptionsHelper; import org.hibernate.metamodel.mapping.internal.FetchOptionsHelper;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.persister.entity.OuterJoinLoadable;
import org.hibernate.type.AssociationType; import org.hibernate.type.AssociationType;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
/** /**
@ -175,7 +175,7 @@ public class BatchFetchStrategyHelperTest extends BaseCoreFunctionalTestCase {
OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getRuntimeMetamodels() OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getRuntimeMetamodels()
.getMappingMetamodel() .getMappingMetamodel()
.getEntityDescriptor(entityClass.getName()); .getEntityDescriptor(entityClass.getName());
int index = ( (UniqueKeyLoadable) entityPersister ).getPropertyIndex( path ); int index = entityPersister.getPropertyIndex( path );
return entityPersister.getFetchMode( index ); return entityPersister.getFetchMode( index );
} }
@ -183,7 +183,7 @@ public class BatchFetchStrategyHelperTest extends BaseCoreFunctionalTestCase {
OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getRuntimeMetamodels() OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getRuntimeMetamodels()
.getMappingMetamodel() .getMappingMetamodel()
.getEntityDescriptor(entityClass.getName()); .getEntityDescriptor(entityClass.getName());
int index = ( (UniqueKeyLoadable) entityPersister ).getPropertyIndex( path ); int index = entityPersister.getPropertyIndex( path );
return (AssociationType) entityPersister.getSubclassPropertyType( index ); return (AssociationType) entityPersister.getSubclassPropertyType( index );
} }

View File

@ -8,24 +8,24 @@ package org.hibernate.orm.test.fetchstrategyhelper;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import org.junit.Test;
import org.hibernate.annotations.Fetch; import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.FetchMode;
import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming; import org.hibernate.engine.FetchTiming;
import org.hibernate.persister.entity.OuterJoinLoadable;
import org.hibernate.persister.entity.UniqueKeyLoadable;
import org.hibernate.metamodel.mapping.internal.FetchOptionsHelper; import org.hibernate.metamodel.mapping.internal.FetchOptionsHelper;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.persister.entity.OuterJoinLoadable;
import org.hibernate.type.AssociationType; import org.hibernate.type.AssociationType;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
/** /**
@ -171,7 +171,7 @@ public class FetchStrategyHelperTest extends BaseCoreFunctionalTestCase {
OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getRuntimeMetamodels() OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getRuntimeMetamodels()
.getMappingMetamodel() .getMappingMetamodel()
.getEntityDescriptor(entityClass.getName()); .getEntityDescriptor(entityClass.getName());
int index = ( (UniqueKeyLoadable) entityPersister ).getPropertyIndex( path ); int index = entityPersister.getPropertyIndex( path );
return entityPersister.getFetchMode( index ); return entityPersister.getFetchMode( index );
} }
@ -179,7 +179,7 @@ public class FetchStrategyHelperTest extends BaseCoreFunctionalTestCase {
OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getRuntimeMetamodels() OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getRuntimeMetamodels()
.getMappingMetamodel() .getMappingMetamodel()
.getEntityDescriptor(entityClass.getName()); .getEntityDescriptor(entityClass.getName());
int index = ( (UniqueKeyLoadable) entityPersister ).getPropertyIndex( path ); int index = entityPersister.getPropertyIndex( path );
return (AssociationType) entityPersister.getSubclassPropertyType( index ); return (AssociationType) entityPersister.getSubclassPropertyType( index );
} }

View File

@ -6,24 +6,23 @@
*/ */
package org.hibernate.orm.test.fetchstrategyhelper; package org.hibernate.orm.test.fetchstrategyhelper;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import org.junit.Test;
import org.hibernate.annotations.Fetch; import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Proxy; import org.hibernate.annotations.Proxy;
import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming; import org.hibernate.engine.FetchTiming;
import org.hibernate.persister.entity.OuterJoinLoadable;
import org.hibernate.persister.entity.UniqueKeyLoadable;
import org.hibernate.metamodel.mapping.internal.FetchOptionsHelper; import org.hibernate.metamodel.mapping.internal.FetchOptionsHelper;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.persister.entity.OuterJoinLoadable;
import org.hibernate.type.AssociationType; import org.hibernate.type.AssociationType;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
/** /**
@ -93,7 +92,7 @@ public class NoProxyFetchStrategyHelperTest extends BaseCoreFunctionalTestCase {
OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getRuntimeMetamodels() OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getRuntimeMetamodels()
.getMappingMetamodel() .getMappingMetamodel()
.getEntityDescriptor(entityClass.getName()); .getEntityDescriptor(entityClass.getName());
int index = ( (UniqueKeyLoadable) entityPersister ).getPropertyIndex( path ); int index = entityPersister.getPropertyIndex( path );
return entityPersister.getFetchMode( index ); return entityPersister.getFetchMode( index );
} }
@ -101,7 +100,7 @@ public class NoProxyFetchStrategyHelperTest extends BaseCoreFunctionalTestCase {
OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getRuntimeMetamodels() OuterJoinLoadable entityPersister = (OuterJoinLoadable) sessionFactory().getRuntimeMetamodels()
.getMappingMetamodel() .getMappingMetamodel()
.getEntityDescriptor(entityClass.getName()); .getEntityDescriptor(entityClass.getName());
int index = ( (UniqueKeyLoadable) entityPersister ).getPropertyIndex( path ); int index = entityPersister.getPropertyIndex( path );
return (AssociationType) entityPersister.getSubclassPropertyType( index ); return (AssociationType) entityPersister.getSubclassPropertyType( index );
} }