HHH-18125 Fix type of embeddable discriminator paths and type literals
Build and store the embeddable discriminator type in the Component. Also, change the type of entity/embeddable type literals to the discriminator type (or `Class` when not polymorphic).
This commit is contained in:
parent
0fd0277745
commit
f7093239d9
|
@ -41,21 +41,31 @@ import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
|||
import org.hibernate.internal.util.ReflectHelper;
|
||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.metamodel.mapping.DiscriminatorConverter;
|
||||
import org.hibernate.metamodel.mapping.DiscriminatorType;
|
||||
import org.hibernate.metamodel.mapping.EmbeddableDiscriminatorConverter;
|
||||
import org.hibernate.metamodel.mapping.internal.DiscriminatorTypeImpl;
|
||||
import org.hibernate.metamodel.spi.EmbeddableInstantiator;
|
||||
import org.hibernate.persister.entity.DiscriminatorHelper;
|
||||
import org.hibernate.property.access.spi.Setter;
|
||||
import org.hibernate.generator.Generator;
|
||||
import org.hibernate.generator.BeforeExecutionGenerator;
|
||||
import org.hibernate.resource.beans.internal.FallbackBeanInstanceProducer;
|
||||
import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.ComponentType;
|
||||
import org.hibernate.type.CompositeType;
|
||||
import org.hibernate.type.EmbeddedComponentType;
|
||||
import org.hibernate.type.UserComponentType;
|
||||
import org.hibernate.type.descriptor.java.JavaType;
|
||||
import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry;
|
||||
import org.hibernate.usertype.CompositeUserType;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static org.hibernate.generator.EventType.INSERT;
|
||||
import static org.hibernate.internal.util.StringHelper.qualify;
|
||||
import static org.hibernate.mapping.MappingHelper.checkPropertyColumnDuplication;
|
||||
import static org.hibernate.metamodel.mapping.EntityDiscriminatorMapping.DISCRIMINATOR_ROLE_NAME;
|
||||
|
||||
/**
|
||||
* A mapping model object that represents an {@linkplain jakarta.persistence.Embeddable embeddable class}.
|
||||
|
@ -77,6 +87,7 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
|
|||
private Boolean isGeneric;
|
||||
private String roleName;
|
||||
private Value discriminator;
|
||||
private transient DiscriminatorType<?> discriminatorType;
|
||||
private Map<Object, String> discriminatorValues;
|
||||
private Map<String, String> subclassToSuperclass;
|
||||
|
||||
|
@ -613,6 +624,30 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
|
|||
this.discriminator = discriminator;
|
||||
}
|
||||
|
||||
public DiscriminatorType<?> getDiscriminatorType() {
|
||||
DiscriminatorType<?> type = discriminatorType;
|
||||
if ( type == null ) {
|
||||
type = discriminatorType = buildDiscriminatorType();
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
private DiscriminatorType<?> buildDiscriminatorType() {
|
||||
return getBuildingContext().getMetadataCollector().resolveEmbeddableDiscriminatorType( getComponentClass(), () -> {
|
||||
final JavaTypeRegistry javaTypeRegistry = getTypeConfiguration().getJavaTypeRegistry();
|
||||
final JavaType<String> domainJavaType = javaTypeRegistry.resolveDescriptor( Class.class );
|
||||
final BasicType<?> discriminatorType = DiscriminatorHelper.getDiscriminatorType( this );
|
||||
final DiscriminatorConverter<String, ?> converter = EmbeddableDiscriminatorConverter.fromValueMappings(
|
||||
qualify( getComponentClassName(), DISCRIMINATOR_ROLE_NAME ),
|
||||
domainJavaType,
|
||||
discriminatorType,
|
||||
getDiscriminatorValues(),
|
||||
getServiceRegistry()
|
||||
);
|
||||
return new DiscriminatorTypeImpl<>( discriminatorType, converter );
|
||||
} );
|
||||
}
|
||||
|
||||
public boolean isPolymorphic() {
|
||||
return discriminator != null;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.hibernate.metamodel.UnsupportedMappingException;
|
|||
import org.hibernate.metamodel.ValueClassification;
|
||||
import org.hibernate.metamodel.mapping.AttributeMapping;
|
||||
import org.hibernate.metamodel.mapping.CompositeIdentifierMapping;
|
||||
import org.hibernate.metamodel.mapping.DiscriminatorType;
|
||||
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
|
||||
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
|
||||
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
|
||||
|
@ -264,8 +263,11 @@ public class AttributeFactory {
|
|||
}
|
||||
}
|
||||
|
||||
final DomainType<?> discriminatorType = component.isPolymorphic() ? component.getDiscriminatorType() : null;
|
||||
final EmbeddableTypeImpl<Y> embeddableType = new EmbeddableTypeImpl<>(
|
||||
context.getJavaTypeRegistry().resolveManagedTypeDescriptor( embeddableClass ),
|
||||
null,
|
||||
discriminatorType,
|
||||
false,
|
||||
context.getJpaMetamodel()
|
||||
);
|
||||
|
@ -287,6 +289,7 @@ public class AttributeFactory {
|
|||
final EmbeddableTypeImpl<?> subType = new EmbeddableTypeImpl<>(
|
||||
context.getJavaTypeRegistry().resolveManagedTypeDescriptor( subclass ),
|
||||
domainTypes.get( component.getSuperclass( subclassName ) ),
|
||||
discriminatorType,
|
||||
false,
|
||||
context.getJpaMetamodel()
|
||||
);
|
||||
|
@ -301,6 +304,8 @@ public class AttributeFactory {
|
|||
private static <Y> EmbeddableTypeImpl<Y> dynamicEmbeddableType(MetadataContext context, Component component) {
|
||||
final EmbeddableTypeImpl<Y> embeddableType = new EmbeddableTypeImpl<>(
|
||||
context.getJavaTypeRegistry().getDescriptor( java.util.Map.class ),
|
||||
null,
|
||||
null,
|
||||
true,
|
||||
context.getJpaMetamodel()
|
||||
);
|
||||
|
|
|
@ -555,6 +555,8 @@ public class MetadataContext {
|
|||
|
||||
final EmbeddableTypeImpl<?> embeddableType = new EmbeddableTypeImpl<>(
|
||||
javaType,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
getJpaMetamodel()
|
||||
);
|
||||
|
|
|
@ -16,9 +16,8 @@ import java.util.function.Function;
|
|||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.metamodel.mapping.internal.EmbeddableDiscriminatorValueDetailsImpl;
|
||||
import org.hibernate.metamodel.model.domain.NavigableRole;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.descriptor.java.JavaType;
|
||||
|
||||
|
@ -35,9 +34,9 @@ public class EmbeddableDiscriminatorConverter<O, R> extends DiscriminatorConvert
|
|||
JavaType<O> domainJavaType,
|
||||
BasicType<R> underlyingJdbcMapping,
|
||||
Map<Object, String> valueMappings,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
ServiceRegistry serviceRegistry) {
|
||||
final List<EmbeddableDiscriminatorValueDetailsImpl> valueDetailsList = new ArrayList<>( valueMappings.size() );
|
||||
final ClassLoaderService cls = sessionFactory.getServiceRegistry().requireService( ClassLoaderService.class );
|
||||
final ClassLoaderService cls = serviceRegistry.requireService( ClassLoaderService.class );
|
||||
valueMappings.forEach( (value, embeddableClassName) -> valueDetailsList.add( new EmbeddableDiscriminatorValueDetailsImpl(
|
||||
value,
|
||||
cls.classForName( embeddableClassName )
|
||||
|
|
|
@ -759,14 +759,6 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme
|
|||
scale = column.getScale();
|
||||
}
|
||||
|
||||
final DiscriminatorType<?> discriminatorType = creationContext.getMetadata().resolveEmbeddableDiscriminatorType(
|
||||
bootDescriptor.getComponentClass(),
|
||||
() -> buildDiscriminatorType(
|
||||
bootDescriptor,
|
||||
creationContext
|
||||
)
|
||||
);
|
||||
|
||||
return new ExplicitColumnDiscriminatorMappingImpl(
|
||||
this,
|
||||
name,
|
||||
|
@ -780,26 +772,10 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme
|
|||
length,
|
||||
precision,
|
||||
scale,
|
||||
discriminatorType
|
||||
bootDescriptor.getDiscriminatorType()
|
||||
);
|
||||
}
|
||||
|
||||
private static DiscriminatorType<?> buildDiscriminatorType(
|
||||
Component bootDescriptor,
|
||||
RuntimeModelCreationContext creationContext) {
|
||||
final JavaTypeRegistry javaTypeRegistry = creationContext.getSessionFactory().getTypeConfiguration().getJavaTypeRegistry();
|
||||
final JavaType<String> domainJavaType = javaTypeRegistry.resolveDescriptor( Class.class );
|
||||
final BasicType<?> discriminatorType = getDiscriminatorType( bootDescriptor );
|
||||
final DiscriminatorConverter<String, ?> converter = EmbeddableDiscriminatorConverter.fromValueMappings(
|
||||
qualify( bootDescriptor.getComponentClassName(), EntityDiscriminatorMapping.DISCRIMINATOR_ROLE_NAME ),
|
||||
domainJavaType,
|
||||
discriminatorType,
|
||||
bootDescriptor.getDiscriminatorValues(),
|
||||
creationContext.getSessionFactory()
|
||||
);
|
||||
return new DiscriminatorTypeImpl<>( discriminatorType, converter );
|
||||
}
|
||||
|
||||
public EmbeddableValuedModelPart getEmbeddedValueMapping() {
|
||||
return valueMapping;
|
||||
}
|
||||
|
|
|
@ -19,21 +19,22 @@ public class AnyDiscriminatorSqmPath<T> extends AbstractSqmPath<T> implements Di
|
|||
|
||||
protected AnyDiscriminatorSqmPath(
|
||||
NavigablePath navigablePath,
|
||||
SqmPathSource referencedPathSource,
|
||||
SqmPath lhs,
|
||||
SqmPathSource<T> referencedPathSource,
|
||||
SqmPath<?> lhs,
|
||||
NodeBuilder nodeBuilder) {
|
||||
super( navigablePath, referencedPathSource, lhs, nodeBuilder );
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnyDiscriminatorSqmPath<T> copy(SqmCopyContext context) {
|
||||
final AnyDiscriminatorSqmPath existing = context.getCopy( this );
|
||||
final AnyDiscriminatorSqmPath<T> existing = context.getCopy( this );
|
||||
if ( existing != null ) {
|
||||
return existing;
|
||||
}
|
||||
//noinspection unchecked
|
||||
return context.registerCopy(
|
||||
this,
|
||||
(AnyDiscriminatorSqmPath) getLhs().copy( context ).type()
|
||||
(AnyDiscriminatorSqmPath<T>) getLhs().copy( context ).type()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.io.Serializable;
|
|||
import java.util.Collection;
|
||||
|
||||
import org.hibernate.metamodel.UnsupportedMappingException;
|
||||
import org.hibernate.metamodel.mapping.EntityDiscriminatorMapping;
|
||||
import org.hibernate.metamodel.model.domain.AbstractManagedType;
|
||||
import org.hibernate.metamodel.model.domain.DomainType;
|
||||
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
|
||||
|
@ -32,21 +33,22 @@ public class EmbeddableTypeImpl<J>
|
|||
extends AbstractManagedType<J>
|
||||
implements EmbeddableDomainType<J>, Serializable {
|
||||
private final boolean isDynamic;
|
||||
|
||||
public EmbeddableTypeImpl(
|
||||
JavaType<J> javaType,
|
||||
boolean isDynamic,
|
||||
JpaMetamodelImplementor domainMetamodel) {
|
||||
this( javaType, null, isDynamic, domainMetamodel );
|
||||
}
|
||||
private final EmbeddedDiscriminatorSqmPathSource<?> discriminatorPathSource;
|
||||
|
||||
public EmbeddableTypeImpl(
|
||||
JavaType<J> javaType,
|
||||
ManagedDomainType<? super J> superType,
|
||||
DomainType<?> discriminatorType,
|
||||
boolean isDynamic,
|
||||
JpaMetamodelImplementor domainMetamodel) {
|
||||
super( javaType.getTypeName(), javaType, superType, domainMetamodel );
|
||||
this.isDynamic = isDynamic;
|
||||
if ( discriminatorType == null ) {
|
||||
this.discriminatorPathSource = null;
|
||||
}
|
||||
else {
|
||||
this.discriminatorPathSource = new EmbeddedDiscriminatorSqmPathSource<>( discriminatorType, this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,7 +87,16 @@ public class EmbeddableTypeImpl<J>
|
|||
return (SqmPathSource<?>) attribute;
|
||||
}
|
||||
|
||||
return (SqmPathSource<?>) findSubTypesAttribute( name );
|
||||
final PersistentAttribute<?, ?> subtypeAttribute = findSubTypesAttribute( name );
|
||||
if ( subtypeAttribute != null ) {
|
||||
return (SqmPathSource<?>) subtypeAttribute;
|
||||
}
|
||||
|
||||
if ( EntityDiscriminatorMapping.matchesRoleName( name ) ) {
|
||||
return discriminatorPathSource;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -35,11 +35,15 @@ public class EmbeddedDiscriminatorSqmPath<T> extends AbstractSqmPath<T> implemen
|
|||
this.embeddableDomainType = embeddableDomainType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmbeddableDomainType<T> getExpressible() {
|
||||
public EmbeddableDomainType<T> getEmbeddableDomainType() {
|
||||
return embeddableDomainType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmbeddedDiscriminatorSqmPathSource<T> getExpressible() {
|
||||
return (EmbeddedDiscriminatorSqmPathSource<T>) getNodeType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmbeddedDiscriminatorSqmPath<T> copy(SqmCopyContext context) {
|
||||
final EmbeddedDiscriminatorSqmPath<T> existing = context.getCopy( this );
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.model.domain.internal;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.DomainType;
|
||||
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
|
||||
import org.hibernate.query.sqm.SqmPathSource;
|
||||
import org.hibernate.query.sqm.tree.domain.SqmPath;
|
||||
|
@ -16,10 +17,10 @@ import org.hibernate.query.sqm.tree.domain.SqmPath;
|
|||
* @author Marco Belladelli
|
||||
*/
|
||||
public class EmbeddedDiscriminatorSqmPathSource<D> extends AbstractDiscriminatorSqmPathSource<D> {
|
||||
private final EmbeddableDomainType<D> embeddableDomainType;
|
||||
private final EmbeddableDomainType<?> embeddableDomainType;
|
||||
|
||||
public EmbeddedDiscriminatorSqmPathSource(EmbeddableDomainType<D> embeddableDomainType) {
|
||||
super( embeddableDomainType );
|
||||
public EmbeddedDiscriminatorSqmPathSource(DomainType<D> discriminatorType, EmbeddableDomainType<?> embeddableDomainType) {
|
||||
super( discriminatorType );
|
||||
this.embeddableDomainType = embeddableDomainType;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,15 +7,11 @@
|
|||
package org.hibernate.metamodel.model.domain.internal;
|
||||
|
||||
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.spi.JpaMetamodelImplementor;
|
||||
import org.hibernate.query.sqm.SqmJoinable;
|
||||
import org.hibernate.query.sqm.SqmPathSource;
|
||||
import org.hibernate.query.sqm.tree.domain.SqmEmbeddedValuedSimplePath;
|
||||
import org.hibernate.query.sqm.tree.domain.SqmPath;
|
||||
|
||||
import static org.hibernate.metamodel.mapping.EntityDiscriminatorMapping.DISCRIMINATOR_ROLE_NAME;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
@ -23,7 +19,6 @@ public class EmbeddedSqmPathSource<J>
|
|||
extends AbstractSqmPathSource<J>
|
||||
implements CompositeSqmPathSource<J> {
|
||||
private final boolean isGeneric;
|
||||
private final EmbeddedDiscriminatorSqmPathSource<?> discriminatorPathSource;
|
||||
|
||||
public EmbeddedSqmPathSource(
|
||||
String localPathName,
|
||||
|
@ -33,12 +28,6 @@ public class EmbeddedSqmPathSource<J>
|
|||
boolean isGeneric) {
|
||||
super( localPathName, pathModel, domainType, jpaBindableType );
|
||||
this.isGeneric = isGeneric;
|
||||
if ( domainType.isPolymorphic() ) {
|
||||
discriminatorPathSource = new EmbeddedDiscriminatorSqmPathSource<>( domainType );
|
||||
}
|
||||
else {
|
||||
discriminatorPathSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,10 +42,6 @@ public class EmbeddedSqmPathSource<J>
|
|||
return subPathSource;
|
||||
}
|
||||
|
||||
if ( name.equals( DISCRIMINATOR_ROLE_NAME ) && discriminatorPathSource != null ) {
|
||||
return discriminatorPathSource;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,11 +12,17 @@ import org.hibernate.dialect.Dialect;
|
|||
import org.hibernate.internal.util.MarkerObject;
|
||||
import org.hibernate.mapping.Component;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.query.sqm.NodeBuilder;
|
||||
import org.hibernate.query.sqm.SqmExpressible;
|
||||
import org.hibernate.query.sqm.SqmPathSource;
|
||||
import org.hibernate.sql.InFragment;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
import org.hibernate.type.Type;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcLiteralFormatter;
|
||||
|
||||
import static org.hibernate.metamodel.mapping.EntityDiscriminatorMapping.DISCRIMINATOR_ROLE_NAME;
|
||||
|
||||
/**
|
||||
* Operations needed by persisters for working with discriminators.
|
||||
*
|
||||
|
@ -109,6 +115,28 @@ public class DiscriminatorHelper {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility that computes the node type used in entity or embeddable type literals. Resolves to
|
||||
* either the {@link org.hibernate.metamodel.mapping.DiscriminatorType}, for polymorphic
|
||||
* domain types, or to {@link StandardBasicTypes#CLASS Class} for non-inherited ones.
|
||||
*/
|
||||
public static <T> SqmExpressible<? super T> getDiscriminatorType(
|
||||
SqmPathSource<T> domainType,
|
||||
NodeBuilder nodeBuilder) {
|
||||
final SqmPathSource<?> subPathSource = domainType.findSubPathSource( DISCRIMINATOR_ROLE_NAME );
|
||||
final SqmExpressible<?> type;
|
||||
if ( subPathSource != null ) {
|
||||
type = subPathSource.getSqmPathType();
|
||||
}
|
||||
else {
|
||||
type = nodeBuilder.getTypeConfiguration()
|
||||
.getBasicTypeRegistry()
|
||||
.resolve( StandardBasicTypes.CLASS );
|
||||
}
|
||||
//noinspection unchecked
|
||||
return (SqmExpressible<? super T>) type;
|
||||
}
|
||||
|
||||
static String discriminatorLiteral(JdbcLiteralFormatter<Object> formatter, Dialect dialect, Object value) {
|
||||
return value == NULL_DISCRIMINATOR || value == NOT_NULL_DISCRIMINATOR
|
||||
? null
|
||||
|
|
|
@ -6,9 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.query.hql.internal;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
|
@ -193,10 +190,10 @@ public class BasicDotIdentifierConsumer implements DotIdentifierConsumer {
|
|||
if ( importableName != null ) {
|
||||
final ManagedDomainType<?> managedType = jpaMetamodel.managedType( importableName );
|
||||
if ( managedType instanceof EntityDomainType<?> ) {
|
||||
return new SqmLiteralEntityType<>( ( (EntityDomainType<?>) managedType ), nodeBuilder );
|
||||
return new SqmLiteralEntityType<>( (EntityDomainType<?>) managedType, nodeBuilder );
|
||||
}
|
||||
else if ( managedType instanceof EmbeddableDomainType<?> ) {
|
||||
return new SqmLiteralEmbeddableType<>( ( (EmbeddableDomainType<?>) managedType ), nodeBuilder );
|
||||
return new SqmLiteralEmbeddableType<>( (EmbeddableDomainType<?>) managedType, nodeBuilder );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7272,13 +7272,10 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
|
||||
@Override
|
||||
public Object visitEmbeddableTypeLiteralExpression(SqmLiteralEmbeddableType<?> expression) {
|
||||
final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
|
||||
// The inferred value mapping for literal embeddable types will either be the
|
||||
// discriminator mapping for polymorphic embeddables or the Class<?> basic type
|
||||
final BasicType<?> basicType = inferredValueMapping != null ?
|
||||
(BasicType<?>) inferredValueMapping.getSingleJdbcMapping() :
|
||||
expression.getNodeType();
|
||||
return new EmbeddableTypeLiteral( expression.getExpressible(), basicType );
|
||||
// The node type of literal embeddable types will either be the discriminator
|
||||
// type for polymorphic embeddables or the Class standard basic type
|
||||
final BasicType<?> basicType = (BasicType<?>) expression.getNodeType();
|
||||
return new EmbeddableTypeLiteral( expression.getEmbeddableDomainType(), basicType );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -170,6 +170,11 @@ public class SqmPluralValuedSimplePath<E> extends AbstractSqmSimplePath<E> {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqmExpression<Class<? extends E>> type() {
|
||||
throw new UnsupportedOperationException( "Cannot access the type of plural valued simple paths" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S extends E> SqmTreatedPath<E, S> treatAs(Class<S> treatJavaType) throws PathException {
|
||||
throw new UnsupportedOperationException( "Cannot treat plural valued simple paths" );
|
||||
|
|
|
@ -16,8 +16,8 @@ import org.hibernate.query.sqm.SqmExpressible;
|
|||
import org.hibernate.query.sqm.tree.SqmCopyContext;
|
||||
import org.hibernate.query.sqm.tree.domain.SqmPath;
|
||||
import org.hibernate.query.sqm.tree.select.SqmSelectableNode;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
import static org.hibernate.persister.entity.DiscriminatorHelper.getDiscriminatorType;
|
||||
|
||||
/**
|
||||
* Represents a reference to an embeddable type as a literal.
|
||||
|
@ -32,13 +32,7 @@ public class SqmLiteralEmbeddableType<T>
|
|||
public SqmLiteralEmbeddableType(
|
||||
EmbeddableDomainType<T> embeddableDomainType,
|
||||
NodeBuilder nodeBuilder) {
|
||||
//noinspection unchecked
|
||||
super(
|
||||
(SqmExpressible<? super T>) nodeBuilder.getTypeConfiguration()
|
||||
.getBasicTypeRegistry()
|
||||
.resolve( StandardBasicTypes.CLASS ),
|
||||
nodeBuilder
|
||||
);
|
||||
super( getDiscriminatorType( embeddableDomainType, nodeBuilder), nodeBuilder );
|
||||
this.embeddableDomainType = embeddableDomainType;
|
||||
}
|
||||
|
||||
|
@ -46,16 +40,6 @@ public class SqmLiteralEmbeddableType<T>
|
|||
return embeddableDomainType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasicType<T> getNodeType() {
|
||||
return (BasicType<T>) super.getNodeType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmbeddableDomainType<T> getExpressible() {
|
||||
return embeddableDomainType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqmLiteralEmbeddableType<T> copy(SqmCopyContext context) {
|
||||
final SqmLiteralEmbeddableType<T> existing = context.getCopy( this );
|
||||
|
|
|
@ -17,6 +17,8 @@ import org.hibernate.query.sqm.tree.SqmCopyContext;
|
|||
import org.hibernate.query.sqm.tree.domain.SqmPath;
|
||||
import org.hibernate.query.sqm.tree.select.SqmSelectableNode;
|
||||
|
||||
import static org.hibernate.persister.entity.DiscriminatorHelper.getDiscriminatorType;
|
||||
|
||||
/**
|
||||
* Represents a reference to an entity type as a literal.
|
||||
* In a restriction like {@code where TYPE(e) = SomeType},
|
||||
|
@ -32,7 +34,7 @@ public class SqmLiteralEntityType<T>
|
|||
private final EntityDomainType<T> entityType;
|
||||
|
||||
public SqmLiteralEntityType(EntityDomainType<T> entityType, NodeBuilder nodeBuilder) {
|
||||
super( entityType, nodeBuilder );
|
||||
super( getDiscriminatorType( entityType, nodeBuilder ), nodeBuilder );
|
||||
this.entityType = entityType;
|
||||
}
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ public class AnyImplicitDiscriminatorTest {
|
|||
scope.inTransaction(
|
||||
session -> {
|
||||
List<ImplicitPropertySet> propertySets = session.createQuery(
|
||||
"select p from ImplicitPropertySet p where type(p.generalProperties) = IntegerProperty ",
|
||||
"select p from ImplicitPropertySet p where type(element(p.generalProperties)) = IntegerProperty ",
|
||||
ImplicitPropertySet.class ).list();
|
||||
assertEquals( 1, propertySets.size() );
|
||||
|
||||
|
@ -152,7 +152,7 @@ public class AnyImplicitDiscriminatorTest {
|
|||
assertEquals( "age", propertySet.getGeneralProperties().get( 0 ).getName() );
|
||||
|
||||
propertySets = session.createQuery(
|
||||
"select p from ImplicitPropertySet p where type(p.generalProperties) = StringProperty ",
|
||||
"select p from ImplicitPropertySet p where type(element(p.generalProperties)) = StringProperty ",
|
||||
ImplicitPropertySet.class ).list();
|
||||
assertEquals( 1, propertySets.size() );
|
||||
|
||||
|
@ -170,7 +170,7 @@ public class AnyImplicitDiscriminatorTest {
|
|||
scope.inTransaction(
|
||||
session -> {
|
||||
List<ImplicitPropertySet> propertySets = session.createQuery(
|
||||
"select p from ImplicitPropertySet p where type(p.generalProperties) = :prop ",
|
||||
"select p from ImplicitPropertySet p where type(element(p.generalProperties)) = :prop ",
|
||||
ImplicitPropertySet.class )
|
||||
.setParameter( "prop", IntegerProperty.class)
|
||||
.list();
|
||||
|
@ -182,7 +182,7 @@ public class AnyImplicitDiscriminatorTest {
|
|||
assertEquals( "age", propertySet.getGeneralProperties().get( 0 ).getName() );
|
||||
|
||||
propertySets = session.createQuery(
|
||||
"select p from ImplicitPropertySet p where type(p.generalProperties) = :prop ",
|
||||
"select p from ImplicitPropertySet p where type(element(p.generalProperties)) = :prop ",
|
||||
ImplicitPropertySet.class )
|
||||
.setParameter( "prop", StringProperty.class)
|
||||
.list();
|
||||
|
|
|
@ -154,7 +154,7 @@ public class AnyTest {
|
|||
scope.inTransaction(
|
||||
session -> {
|
||||
List<PropertySet> propertySets = session.createQuery(
|
||||
"select p from PropertySet p where type(p.generalProperties) = IntegerProperty ",
|
||||
"select p from PropertySet p where type(element(p.generalProperties)) = IntegerProperty ",
|
||||
PropertySet.class ).list();
|
||||
assertEquals( 1, propertySets.size() );
|
||||
|
||||
|
@ -164,7 +164,7 @@ public class AnyTest {
|
|||
assertEquals( "age", propertySet.getGeneralProperties().get( 0 ).getName() );
|
||||
|
||||
propertySets = session.createQuery(
|
||||
"select p from PropertySet p where type(p.generalProperties) = StringProperty ",
|
||||
"select p from PropertySet p where type(element(p.generalProperties)) = StringProperty ",
|
||||
PropertySet.class ).list();
|
||||
assertEquals( 1, propertySets.size() );
|
||||
|
||||
|
@ -182,7 +182,7 @@ public class AnyTest {
|
|||
scope.inTransaction(
|
||||
session -> {
|
||||
List<PropertySet> propertySets = session.createQuery(
|
||||
"select p from PropertySet p where type(p.generalProperties) = :prop ",
|
||||
"select p from PropertySet p where type(element(p.generalProperties)) = :prop ",
|
||||
PropertySet.class )
|
||||
.setParameter( "prop", IntegerProperty.class)
|
||||
.list();
|
||||
|
@ -194,7 +194,7 @@ public class AnyTest {
|
|||
assertEquals( "age", propertySet.getGeneralProperties().get( 0 ).getName() );
|
||||
|
||||
propertySets = session.createQuery(
|
||||
"select p from PropertySet p where type(p.generalProperties) = :prop ",
|
||||
"select p from PropertySet p where type(element(p.generalProperties)) = :prop ",
|
||||
PropertySet.class )
|
||||
.setParameter( "prop", StringProperty.class)
|
||||
.list();
|
||||
|
|
|
@ -110,11 +110,11 @@ public class ElementCollectionEmbeddableInheritanceTest {
|
|||
public void testType(SessionFactoryScope scope) {
|
||||
scope.inTransaction( session -> {
|
||||
assertThat( session.createQuery(
|
||||
"select type(t.embeddables) from TestEntity t where id = 2",
|
||||
"select type(element(t.embeddables)) from TestEntity t where id = 2",
|
||||
Class.class
|
||||
).getSingleResult() ).isEqualTo( SubChildOneEmbeddable.class );
|
||||
assertThat( session.createQuery(
|
||||
"select t.id from TestEntity t where type(t.embeddables) = SubChildOneEmbeddable",
|
||||
"select t.id from TestEntity t where type(element(t.embeddables)) = SubChildOneEmbeddable",
|
||||
Long.class
|
||||
).getSingleResult() ).isEqualTo( 2L );
|
||||
assertThat( session.createQuery(
|
||||
|
|
|
@ -1130,7 +1130,7 @@ public abstract class MockSessionFactory
|
|||
|
||||
private EmbeddableTypeImpl<?> createEmbeddableDomainType(String entityName, CompositeType compositeType, ManagedDomainType<?> owner) {
|
||||
final JavaType<Object> javaType = new UnknownBasicJavaType<>(Object.class, compositeType.getReturnedClassName());
|
||||
return new EmbeddableTypeImpl<>(javaType, true, metamodel.getJpaMetamodel()) {
|
||||
return new EmbeddableTypeImpl<>( javaType, null, null, true, metamodel.getJpaMetamodel() ) {
|
||||
@Override
|
||||
public PersistentAttribute<Object, Object> findAttribute(String name) {
|
||||
return createAttribute(
|
||||
|
|
Loading…
Reference in New Issue