Fix EmbeddableMappingType trowing exception wehen the attributeMapping is an instance of EmbeddedAttributeMapping

This commit is contained in:
Andrea Boriero 2021-11-05 16:08:51 +01:00 committed by Christian Beikov
parent 55b1ec48f1
commit 07a314b663
39 changed files with 264 additions and 178 deletions

View File

@ -0,0 +1,16 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.metamodel;
import org.hibernate.HibernateException;
import org.hibernate.metamodel.mapping.NonTransientException;
public class MetamodelUnsupportedOperationException extends HibernateException implements NonTransientException {
public MetamodelUnsupportedOperationException(String message) {
super( message );
}
}

View File

@ -24,6 +24,7 @@ import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Value;
import org.hibernate.metamodel.AttributeClassification;
import org.hibernate.metamodel.MetamodelUnsupportedOperationException;
import org.hibernate.metamodel.RepresentationMode;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.model.domain.AbstractIdentifiableType;
@ -493,7 +494,7 @@ public class AttributeFactory {
context
);
}
throw new UnsupportedOperationException( "oops, we are missing something: " + propertyMapping );
throw new MetamodelUnsupportedOperationException( "oops, we are missing something: " + propertyMapping );
}
public static AttributeClassification determineSingularAssociationClassification(Member member) {

View File

@ -36,6 +36,7 @@ import org.hibernate.mapping.IndexedConsumer;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.Table;
import org.hibernate.metamodel.MetamodelUnsupportedOperationException;
import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping;
import org.hibernate.metamodel.mapping.internal.DiscriminatedAssociationAttributeMapping;
import org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping;
@ -233,8 +234,12 @@ public class EmbeddableMappingType implements ManagedMappingType, SelectableMapp
attributeMapping = toOne;
currentIndex += attributeMapping.getJdbcTypeCount();
}
else if ( attributeMapping instanceof EmbeddedAttributeMapping ) {
attributeMapping = ( (EmbeddedAttributeMapping) attributeMapping ).copy( declaringType );
currentIndex = attributeMapping.getJdbcTypeCount();
}
else {
throw new UnsupportedOperationException(
throw new MetamodelUnsupportedOperationException(
"Only basic and to-one attributes are supported in composite fks" );
}
this.attributeMappings.add( attributeMapping );

View File

@ -18,6 +18,7 @@ import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.loader.ast.spi.Loadable;
import org.hibernate.loader.ast.spi.MultiNaturalIdLoader;
import org.hibernate.loader.ast.spi.NaturalIdLoader;
import org.hibernate.metamodel.MetamodelUnsupportedOperationException;
import org.hibernate.metamodel.spi.EntityRepresentationStrategy;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.query.NavigablePath;
@ -354,7 +355,7 @@ public interface EntityMappingType extends ManagedMappingType, EntityValuedModel
SqlAliasBase sqlAliasBase,
SqlExpressionResolver sqlExpressionResolver,
SqlAstCreationContext creationContext) {
throw new UnsupportedOperationException(
throw new MetamodelUnsupportedOperationException(
"Entity mapping does not support primary TableReference creation [" +
getClass().getName() + " : " + getEntityName() + "]"
);
@ -366,7 +367,7 @@ public interface EntityMappingType extends ManagedMappingType, EntityValuedModel
TableReference lhs,
SqlExpressionResolver sqlExpressionResolver,
SqlAstCreationContext creationContext) {
throw new UnsupportedOperationException(
throw new MetamodelUnsupportedOperationException(
"Entity mapping does not support primary TableReference join creation [" +
getClass().getName() + " : " + getEntityName() + "]"
);

View File

@ -25,6 +25,7 @@ import org.hibernate.loader.ast.internal.MultiNaturalIdLoaderStandard;
import org.hibernate.loader.ast.spi.MultiNaturalIdLoader;
import org.hibernate.loader.ast.spi.NaturalIdLoader;
import org.hibernate.mapping.IndexedConsumer;
import org.hibernate.metamodel.MetamodelUnsupportedOperationException;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
import org.hibernate.metamodel.mapping.JdbcMapping;
@ -155,7 +156,7 @@ public class CompoundNaturalIdMapping extends AbstractNaturalIdMapping implement
return values;
}
throw new UnsupportedOperationException( "Do not know how to normalize compound natural-id value : " + incoming );
throw new MetamodelUnsupportedOperationException( "Do not know how to normalize compound natural-id value : " + incoming );
}
@Override

View File

@ -14,6 +14,7 @@ import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.EntityMappingType;
@ -81,6 +82,35 @@ public class EmbeddedAttributeMapping
ManagedMappingType declaringType,
PropertyAccess propertyAccess,
ValueGeneration valueGeneration) {
this(
name,
navigableRole,
stateArrayPosition,
tableExpression,
attributeMetadataAccess,
getPropertyAccess(parentInjectionAttributeName, embeddableMappingType),
mappedFetchTiming,
mappedFetchStyle,
embeddableMappingType,
declaringType,
propertyAccess,
valueGeneration
);
}
public EmbeddedAttributeMapping(
String name,
NavigableRole navigableRole,
int stateArrayPosition,
String tableExpression,
StateArrayContributorMetadataAccess attributeMetadataAccess,
PropertyAccess parentInjectionAttributePropertyAccess,
FetchTiming mappedFetchTiming,
FetchStyle mappedFetchStyle,
EmbeddableMappingType embeddableMappingType,
ManagedMappingType declaringType,
PropertyAccess propertyAccess,
ValueGeneration valueGeneration) {
super(
name,
stateArrayPosition,
@ -93,19 +123,11 @@ public class EmbeddedAttributeMapping
);
this.navigableRole = navigableRole;
if ( parentInjectionAttributeName != null ) {
parentInjectionAttributePropertyAccess = PropertyAccessStrategyBasicImpl.INSTANCE.buildPropertyAccess(
embeddableMappingType.getMappedJavaTypeDescriptor().getJavaTypeClass(),
parentInjectionAttributeName
);
}
else {
parentInjectionAttributePropertyAccess = null;
}
this.parentInjectionAttributePropertyAccess = parentInjectionAttributePropertyAccess;
this.tableExpression = tableExpression;
this.embeddableMappingType = embeddableMappingType;
}
// Constructor is only used for creating the inverse attribute mapping
@ -345,4 +367,37 @@ public class EmbeddedAttributeMapping
public String toString() {
return "EmbeddedAttributeMapping(" + navigableRole + ")@" + System.identityHashCode( this );
}
public AttributeMapping copy(ManagedMappingType declaringType) {
return new EmbeddedAttributeMapping(
getAttributeName(),
getNavigableRole(),
getStateArrayPosition(),
tableExpression,
getAttributeMetadataAccess(),
getParentInjectionAttributePropertyAccess(),
getTiming(),
getStyle(),
getEmbeddableTypeDescriptor(),
declaringType,
getPropertyAccess(),
getValueGeneration()
);
}
private static PropertyAccess getPropertyAccess(
String parentInjectionAttributeName,
EmbeddableMappingType embeddableMappingType) {
final PropertyAccess parentInjectionAttributePropertyAccess;
if ( parentInjectionAttributeName != null ) {
parentInjectionAttributePropertyAccess = PropertyAccessStrategyBasicImpl.INSTANCE.buildPropertyAccess(
embeddableMappingType.getMappedJavaTypeDescriptor().getJavaTypeClass(),
parentInjectionAttributeName
);
}
else {
parentInjectionAttributePropertyAccess = null;
}
return parentInjectionAttributePropertyAccess;
}
}

View File

@ -17,6 +17,7 @@ import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.loader.ast.internal.LoaderSelectBuilder;
import org.hibernate.metamodel.MetamodelUnsupportedOperationException;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.GeneratedValueResolver;
import org.hibernate.metamodel.mapping.InDatabaseGeneratedValueResolver;
@ -165,7 +166,7 @@ public class GeneratedValuesProcessor {
@Override
public Callback getCallback() {
throw new UnsupportedOperationException( "Follow-on locking not supported yet" );
throw new MetamodelUnsupportedOperationException( "Follow-on locking not supported yet" );
}
},

View File

@ -7,6 +7,7 @@
package org.hibernate.metamodel.mapping.internal;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.metamodel.MetamodelUnsupportedOperationException;
import org.hibernate.metamodel.mapping.GeneratedValueResolver;
import org.hibernate.tuple.GenerationTiming;
@ -26,6 +27,6 @@ public class NoGeneratedValueResolver implements GeneratedValueResolver {
@Override
public Object resolveGeneratedValue(Object[] row, Object entity, SharedSessionContractImplementor session) {
throw new UnsupportedOperationException( "NoGeneratedValueResolver does not support generated values" );
throw new MetamodelUnsupportedOperationException( "NoGeneratedValueResolver does not support generated values" );
}
}

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.metamodel.mapping.ordering.ast;
import org.hibernate.metamodel.MetamodelUnsupportedOperationException;
import org.hibernate.metamodel.mapping.MappingType;
import org.hibernate.metamodel.mapping.ModelPartContainer;
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
@ -54,7 +55,7 @@ public class ColumnReference implements OrderingExpression, SequencePart {
String name,
boolean isTerminal,
TranslationContext translationContext) {
throw new UnsupportedOperationException( "ColumnReference cannot be de-referenced" );
throw new MetamodelUnsupportedOperationException( "ColumnReference cannot be de-referenced" );
}
@Override

View File

@ -15,6 +15,7 @@ import jakarta.persistence.metamodel.Bindable;
import jakarta.persistence.metamodel.IdentifiableType;
import jakarta.persistence.metamodel.SingularAttribute;
import org.hibernate.metamodel.MetamodelUnsupportedOperationException;
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
import org.hibernate.metamodel.model.domain.internal.BasicSqmPathSource;
import org.hibernate.metamodel.model.domain.internal.EmbeddedSqmPathSource;
@ -417,7 +418,7 @@ public abstract class AbstractIdentifiableType<J>
}
else {
if ( isIdMappingRequired() ) {
throw new UnsupportedOperationException( "Could not build SqmPathSource for entity identifier : " + getTypeName() );
throw new MetamodelUnsupportedOperationException( "Could not build SqmPathSource for entity identifier : " + getTypeName() );
}
return null;
}

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.metamodel.model.domain.internal;
import org.hibernate.metamodel.MetamodelUnsupportedOperationException;
import org.hibernate.metamodel.model.domain.AnyMappingDomainType;
import org.hibernate.metamodel.model.domain.BasicDomainType;
import org.hibernate.query.NavigablePath;
@ -42,7 +43,7 @@ public class AnyMappingSqmPathSource<J> extends AbstractSqmPathSource<J> {
return keyPathSource;
}
throw new UnsupportedOperationException( "De-referencing parts of an ANY mapping, other than the key, is not supported" );
throw new MetamodelUnsupportedOperationException( "De-referencing parts of an ANY mapping, other than the key, is not supported" );
}
@Override

View File

@ -9,6 +9,7 @@ package org.hibernate.metamodel.model.domain.internal;
import java.util.Arrays;
import java.util.List;
import org.hibernate.metamodel.MetamodelUnsupportedOperationException;
import org.hibernate.metamodel.mapping.MappingModelExpressable;
import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType;
import org.hibernate.metamodel.model.domain.AllowableParameterType;
@ -46,12 +47,12 @@ public class ArrayTupleType implements TupleType<Object[]>, AllowableParameterTy
@Override
public String getComponentName(int index) {
throw new UnsupportedOperationException( "Array tuple has no component names" );
throw new MetamodelUnsupportedOperationException( "Array tuple has no component names" );
}
@Override
public List<String> getComponentNames() {
throw new UnsupportedOperationException( "Array tuple has no component names" );
throw new MetamodelUnsupportedOperationException( "Array tuple has no component names" );
}
@Override
@ -61,7 +62,7 @@ public class ArrayTupleType implements TupleType<Object[]>, AllowableParameterTy
@Override
public SqmExpressable<?> get(String componentName) {
throw new UnsupportedOperationException( "Array tuple has no component names" );
throw new MetamodelUnsupportedOperationException( "Array tuple has no component names" );
}
@Override

View File

@ -9,6 +9,7 @@ package org.hibernate.metamodel.model.domain.internal;
import java.util.List;
import java.util.Set;
import org.hibernate.metamodel.MetamodelUnsupportedOperationException;
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
import org.hibernate.metamodel.model.domain.PersistentAttribute;
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
@ -30,7 +31,7 @@ public interface AttributeContainer<J> {
* or an aggregated composite id ({@link jakarta.persistence.EmbeddedId})
*/
default void applyIdAttribute(SingularPersistentAttribute<J, ?> idAttribute) {
throw new UnsupportedOperationException(
throw new MetamodelUnsupportedOperationException(
"AttributeContainer [" + getClass().getName() + "] does not support identifiers"
);
}
@ -38,7 +39,7 @@ public interface AttributeContainer<J> {
default void applyNonAggregatedIdAttributes(
Set<SingularPersistentAttribute<? super J, ?>> idAttributes,
EmbeddableDomainType<?> idClassType) {
throw new UnsupportedOperationException(
throw new MetamodelUnsupportedOperationException(
"AttributeContainer [" + getClass().getName() + "] does not support identifiers"
);
}
@ -49,13 +50,13 @@ public interface AttributeContainer<J> {
* because of its dependence on declaring-type, etc that we may not be able to do
*/
default void applyIdClassAttributes(Set<SingularPersistentAttribute<? super J, ?>> idClassAttributes) {
throw new UnsupportedOperationException(
throw new MetamodelUnsupportedOperationException(
"AttributeContainer [" + getClass().getName() + "] does not support identifiers"
);
}
default void applyVersionAttribute(SingularPersistentAttribute<J, ?> versionAttribute) {
throw new UnsupportedOperationException(
throw new MetamodelUnsupportedOperationException(
"AttributeContainer [" + getClass().getName() + "] does not support versions"
);
}

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.metamodel.model.domain.internal;
import org.hibernate.metamodel.MetamodelUnsupportedOperationException;
import org.hibernate.metamodel.mapping.EntityDiscriminatorMapping;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.EntityValuedModelPart;
@ -92,11 +93,11 @@ public class DiscriminatorSqmPath extends AbstractSqmPath implements SelfInterpr
@Override
public SqmTreatedPath treatAs(Class treatJavaType) throws PathException {
throw new UnsupportedOperationException( "Cannot apply TREAT operator to discriminator path" );
throw new MetamodelUnsupportedOperationException( "Cannot apply TREAT operator to discriminator path" );
}
@Override
public SqmTreatedPath treatAs(EntityDomainType treatTarget) throws PathException {
throw new UnsupportedOperationException( "Cannot apply TREAT operator to discriminator path" );
throw new MetamodelUnsupportedOperationException( "Cannot apply TREAT operator to discriminator path" );
}
}

View File

@ -13,6 +13,8 @@ import jakarta.persistence.metamodel.EntityType;
import org.hibernate.graph.internal.SubGraphImpl;
import org.hibernate.graph.spi.SubGraphImplementor;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.metamodel.MetamodelUnsupportedOperationException;
import org.hibernate.metamodel.MetamodelUnsupportedOperationException;
import org.hibernate.metamodel.mapping.EntityDiscriminatorMapping;
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
import org.hibernate.metamodel.model.domain.AbstractIdentifiableType;
@ -187,7 +189,7 @@ public class EntityTypeImpl<J>
@Override
public SqmPath<J> createSqmPath(SqmPath<?> lhs, SqmPathSource<?> intermediatePathSource) {
throw new UnsupportedOperationException(
throw new MetamodelUnsupportedOperationException(
"EntityType cannot be used to create an SqmPath - that would be an SqmFrom which are created directly"
);
}

View File

@ -47,6 +47,7 @@ import org.hibernate.mapping.Component;
import org.hibernate.mapping.MappedSuperclass;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.metamodel.MappingMetamodel;
import org.hibernate.metamodel.MetamodelUnsupportedOperationException;
import org.hibernate.metamodel.internal.JpaStaticMetaModelPopulationSetting;
import org.hibernate.metamodel.mapping.MappingModelExpressable;
import org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess;
@ -766,13 +767,10 @@ public class MappingMetamodelImpl implements MappingMetamodel, MetamodelImplemen
}
@Override
public MappingModelExpressable lenientlyResolveMappingExpressable(SqmExpressable<?> sqmExpressable, Function<NavigablePath, TableGroup> tableGroupLocator) {
try {
return resolveMappingExpressable( sqmExpressable, tableGroupLocator );
}
catch (UnsupportedOperationException e) {
return null;
}
public MappingModelExpressable lenientlyResolveMappingExpressable(
SqmExpressable<?> sqmExpressable,
Function<NavigablePath, TableGroup> tableGroupLocator) {
return resolveMappingExpressable( sqmExpressable, tableGroupLocator );
}
@ -831,8 +829,7 @@ public class MappingMetamodelImpl implements MappingMetamodel, MetamodelImplemen
? createdMappingModelExpressable
: existingMappingModelExpressable;
}
throw new UnsupportedOperationException( "Cannot determine proper mapping model expressable for " + sqmExpressable );
return null;
}
@Override

View File

@ -15,6 +15,7 @@ import java.util.Set;
import org.hibernate.mapping.Property;
import org.hibernate.metamodel.AttributeClassification;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.metamodel.MetamodelUnsupportedOperationException;
import org.hibernate.metamodel.internal.AttributeFactory;
import org.hibernate.metamodel.internal.MetadataContext;
import org.hibernate.metamodel.internal.PluralAttributeMetadata;
@ -124,7 +125,7 @@ public class PluralAttributeBuilder<D, C, E, K> {
return new BagAttributeImpl<>( builder, metadataContext );
}
throw new UnsupportedOperationException( "Unknown collection: " + attributeJtd.getJavaType() );
throw new MetamodelUnsupportedOperationException( "Unknown collection: " + attributeJtd.getJavaType() );
}
private static SimpleDomainType<?> determineListIndexOrMapKeyType(

View File

@ -46,6 +46,7 @@ import org.hibernate.internal.util.collections.StandardStack;
import org.hibernate.loader.MultipleBagFetchException;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.metamodel.MappingMetamodel;
import org.hibernate.metamodel.MetamodelUnsupportedOperationException;
import org.hibernate.metamodel.mapping.Association;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.BasicValuedMapping;
@ -3587,13 +3588,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
}
protected MappingModelExpressable<?> lenientlyResolveMappingExpressable(SqmExpressable<?> nodeType) {
try {
return resolveMappingExpressable( nodeType );
}
catch (UnsupportedOperationException e) {
// todo (6.0) : log?
return null;
}
return resolveMappingExpressable( nodeType );
}
protected MappingModelExpressable<?> resolveMappingExpressable(SqmExpressable<?> nodeType) {
@ -4544,14 +4539,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
}
private MappingModelExpressable<?> determineCurrentExpressable(SqmTypedNode<?> expression) {
try {
return creationContext
.getDomainModel()
.resolveMappingExpressable( expression.getNodeType(), getFromClauseIndex()::findTableGroup );
}
catch (UnsupportedOperationException e) {
return null;
}
return creationContext
.getDomainModel()
.resolveMappingExpressable( expression.getNodeType(), getFromClauseIndex()::findTableGroup );
}
private <X> X visitWithInferredType(SqmExpression<?> expression, SqmExpression<?> inferred) {
@ -4567,28 +4557,23 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
private <X> X visitWithLenientInferredType(SqmExpression<?> expression, SqmExpression<?> inferred) {
inferrableTypeAccessStack.push(
() -> {
try {
final MappingModelExpressable<?> definedType = creationContext
.getDomainModel()
.resolveMappingExpressable( expression.getNodeType(), getFromClauseIndex()::findTableGroup );
if ( definedType != null ) {
return definedType;
}
MappingModelExpressable<?> definedType = creationContext
.getDomainModel()
.resolveMappingExpressable(
expression.getNodeType(),
getFromClauseIndex()::findTableGroup
);
if ( definedType != null ) {
return definedType;
}
catch (UnsupportedOperationException ignore) {
// todo (6.0) : log?
}
try {
final MappingModelExpressable<?> definedType = creationContext
.getDomainModel()
.lenientlyResolveMappingExpressable( inferred.getNodeType(), getFromClauseIndex()::findTableGroup );
if ( definedType != null ) {
return definedType;
}
}
catch (UnsupportedOperationException ignore) {
// todo (6.0) : log?
definedType = creationContext
.getDomainModel()
.lenientlyResolveMappingExpressable(
inferred.getNodeType(),
getFromClauseIndex()::findTableGroup
);
if ( definedType != null ) {
return definedType;
}
return null;

View File

@ -7,7 +7,7 @@
// $Id:$
package org.hibernate.test.annotations.derivedidentities;
package org.hibernate.orm.test.annotations.derivedidentities;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;

View File

@ -7,7 +7,7 @@
// $Id:$
package org.hibernate.test.annotations.derivedidentities;
package org.hibernate.orm.test.annotations.derivedidentities;
import java.io.Serializable;
import jakarta.persistence.Embeddable;

View File

@ -6,7 +6,7 @@
*/
// $Id:$
package org.hibernate.test.annotations.derivedidentities;
package org.hibernate.orm.test.annotations.derivedidentities;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;

View File

@ -7,7 +7,7 @@
// $Id:$
package org.hibernate.test.annotations.derivedidentities;
package org.hibernate.orm.test.annotations.derivedidentities;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;

View File

@ -7,7 +7,7 @@
// $Id:$
package org.hibernate.test.annotations.derivedidentities;
package org.hibernate.orm.test.annotations.derivedidentities;
import java.io.Serializable;
/**

View File

@ -7,7 +7,7 @@
// $Id:$
package org.hibernate.test.annotations.derivedidentities;
package org.hibernate.orm.test.annotations.derivedidentities;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;

View File

@ -7,7 +7,7 @@
// $Id:$
package org.hibernate.test.annotations.derivedidentities;
package org.hibernate.orm.test.annotations.derivedidentities;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;

View File

@ -1,4 +1,4 @@
package org.hibernate.test.annotations.derivedidentities.e3.b2;
package org.hibernate.orm.test.annotations.derivedidentities.e3.b2;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;

View File

@ -1,4 +1,4 @@
package org.hibernate.test.annotations.derivedidentities.e3.b2;
package org.hibernate.orm.test.annotations.derivedidentities.e3.b2;
import jakarta.persistence.Embeddable;
import java.io.Serializable;

View File

@ -21,67 +21,72 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.derivedidentities.e3.b2;
package org.hibernate.orm.test.annotations.derivedidentities.e3.b2;
import org.hibernate.Session;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.orm.test.util.SchemaUtil;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Emmanuel Bernard
* @author Matt Drees
*/
public class DerivedIdentityEmbeddedIdParentEmbeddedIdGrandparentEmbeddedIdDepTest extends BaseNonConfigCoreFunctionalTestCase {
@DomainModel(
annotatedClasses = { Policy.class, Dependent.class, Employee.class }
)
@SessionFactory
public class DerivedIdentityEmbeddedIdParentEmbeddedIdGrandparentEmbeddedIdDepTest {
@Test
public void testManyToOne() throws Exception {
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_firstName", metadata() ) );
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_lastName", metadata() ) );
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "name", metadata() ) );
assertTrue( !SchemaUtil.isColumnPresent( "Dependent", "firstName", metadata() ) );
assertTrue( !SchemaUtil.isColumnPresent( "Dependent", "lastName", metadata() ) );
public void testManyToOne(SessionFactoryScope scope) {
final MetadataImplementor metadata = scope.getMetadataImplementor();
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_firstName", metadata ) );
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_lastName", metadata ) );
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "name", metadata ) );
assertTrue( !SchemaUtil.isColumnPresent( "Dependent", "firstName", metadata ) );
assertTrue( !SchemaUtil.isColumnPresent( "Dependent", "lastName", metadata ) );
assertTrue( SchemaUtil.isColumnPresent( "Policy", "dep_emp_firstName", metadata() ) );
assertTrue( SchemaUtil.isColumnPresent( "Policy", "dep_emp_lastName", metadata() ) );
assertTrue( SchemaUtil.isColumnPresent( "Policy", "type", metadata() ) );
assertTrue( !SchemaUtil.isColumnPresent( "Policy", "firstName", metadata() ) );
assertTrue( !SchemaUtil.isColumnPresent( "Policy", "lastName", metadata() ) );
assertTrue( !SchemaUtil.isColumnPresent( "Policy", "name", metadata() ) );
assertTrue( SchemaUtil.isColumnPresent( "Policy", "dep_emp_firstName", metadata ) );
assertTrue( SchemaUtil.isColumnPresent( "Policy", "dep_emp_lastName", metadata ) );
assertTrue( SchemaUtil.isColumnPresent( "Policy", "type", metadata ) );
assertTrue( !SchemaUtil.isColumnPresent( "Policy", "firstName", metadata ) );
assertTrue( !SchemaUtil.isColumnPresent( "Policy", "lastName", metadata ) );
assertTrue( !SchemaUtil.isColumnPresent( "Policy", "name", metadata ) );
final Employee e = new Employee();
e.empId = new EmployeeId();
e.empId.firstName = "Emmanuel";
e.empId.lastName = "Bernard";
final Session s = openSession();
s.getTransaction().begin();
s.persist( e );
final Dependent d = new Dependent();
d.emp = e;
d.id = new DependentId();
d.id.name = "Doggy";
s.persist( d );
Policy p = new Policy();
p.dep = d;
p.id = new PolicyId();
p.id.type = "Vet Insurance";
s.persist( p );
s.flush();
s.clear();
p = (Policy) s.get( Policy.class, p.id );
assertNotNull( p.dep );
assertEquals( e.empId.firstName, p.dep.emp.empId.firstName );
s.getTransaction().rollback();
s.close();
}
scope.inTransaction(
session -> {
session.persist( e );
final Dependent d = new Dependent();
d.emp = e;
d.id = new DependentId();
d.id.name = "Doggy";
session.persist( d );
Policy p = new Policy();
p.dep = d;
p.id = new PolicyId();
p.id.type = "Vet Insurance";
session.persist( p );
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[]{Policy.class, Dependent.class, Employee.class};
session.flush();
session.clear();
p = session.get( Policy.class, p.id );
assertNotNull( p.dep );
assertEquals( e.empId.firstName, p.dep.emp.empId.firstName );
}
);
}
}

View File

@ -1,4 +1,4 @@
package org.hibernate.test.annotations.derivedidentities.e3.b3;
package org.hibernate.orm.test.annotations.derivedidentities.e3.b2;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;

View File

@ -1,4 +1,4 @@
package org.hibernate.test.annotations.derivedidentities.e3.b3;
package org.hibernate.orm.test.annotations.derivedidentities.e3.b2;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;

View File

@ -1,4 +1,4 @@
package org.hibernate.test.annotations.derivedidentities.e3.b2;
package org.hibernate.orm.test.annotations.derivedidentities.e3.b2;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;

View File

@ -1,4 +1,4 @@
package org.hibernate.test.annotations.derivedidentities.e3.b2;
package org.hibernate.orm.test.annotations.derivedidentities.e3.b2;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;

View File

@ -1,4 +1,4 @@
package org.hibernate.test.annotations.derivedidentities.e3.b3;
package org.hibernate.orm.test.annotations.derivedidentities.e3.b3;
import jakarta.persistence.*;

View File

@ -1,4 +1,4 @@
package org.hibernate.test.annotations.derivedidentities.e3.b3;
package org.hibernate.orm.test.annotations.derivedidentities.e3.b3;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;

View File

@ -21,61 +21,70 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.derivedidentities.e3.b3;
package org.hibernate.orm.test.annotations.derivedidentities.e3.b3;
import org.hibernate.Session;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.orm.test.util.SchemaUtil;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test;
import static org.junit.Assert.*;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Emmanuel Bernard
* @author Matt Drees
*/
public class DerivedIdentityEmbeddedIdParentEmbeddedIdGrandparentEmbeddedIdColumnOverridesDepTest extends BaseNonConfigCoreFunctionalTestCase {
@Test
public void testManyToOne() throws Exception {
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FIRSTNAME", metadata() ) );
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "LASTNAME", metadata() ) );
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "name", metadata() ) );
@DomainModel(
annotatedClasses = { Policy.class, Dependent.class, Employee.class }
)
@SessionFactory
public class DerivedIdentityEmbeddedIdParentEmbeddedIdGrandparentEmbeddedIdColumnOverridesDepTest {
assertTrue( SchemaUtil.isColumnPresent( "Policy", "FIRSTNAME", metadata() ) );
assertTrue( SchemaUtil.isColumnPresent( "Policy", "LASTNAME", metadata() ) );
assertTrue( SchemaUtil.isColumnPresent( "Policy", "NAME", metadata() ) );
assertTrue( SchemaUtil.isColumnPresent( "Policy", "type", metadata() ) );
@Test
public void testManyToOne(SessionFactoryScope scope) {
final MetadataImplementor metadata = scope.getMetadataImplementor();
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FIRSTNAME", metadata ) );
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "LASTNAME", metadata ) );
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "name", metadata ) );
assertTrue( SchemaUtil.isColumnPresent( "Policy", "FIRSTNAME", metadata ) );
assertTrue( SchemaUtil.isColumnPresent( "Policy", "LASTNAME", metadata ) );
assertTrue( SchemaUtil.isColumnPresent( "Policy", "NAME", metadata ) );
assertTrue( SchemaUtil.isColumnPresent( "Policy", "type", metadata ) );
final Employee e = new Employee();
e.empId = new EmployeeId();
e.empId.firstName = "Emmanuel";
e.empId.lastName = "Bernard";
final Session s = openSession();
s.getTransaction().begin();
s.persist( e );
final Dependent d = new Dependent();
d.emp = e;
d.id = new DependentId();
d.id.name = "Doggy";
s.persist( d );
Policy p = new Policy();
p.dep = d;
p.id = new PolicyId();
p.id.type = "Vet Insurance";
s.persist( p );
s.flush();
s.clear();
p = (Policy) s.get( Policy.class, p.id );
assertNotNull( p.dep );
assertEquals( e.empId.firstName, p.dep.emp.empId.firstName );
s.getTransaction().rollback();
s.close();
scope.inTransaction(
session -> {
session.persist( e );
final Dependent d = new Dependent();
d.emp = e;
d.id = new DependentId();
d.id.name = "Doggy";
session.persist( d );
Policy p = new Policy();
p.dep = d;
p.id = new PolicyId();
p.id.type = "Vet Insurance";
session.persist( p );
session.flush();
session.clear();
p = session.get( Policy.class, p.id );
assertNotNull( p.dep );
assertEquals( e.empId.firstName, p.dep.emp.empId.firstName );
}
);
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[]{Policy.class, Dependent.class, Employee.class};
}
}

View File

@ -1,4 +1,4 @@
package org.hibernate.test.annotations.derivedidentities.e3.b2;
package org.hibernate.orm.test.annotations.derivedidentities.e3.b3;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;

View File

@ -1,4 +1,4 @@
package org.hibernate.test.annotations.derivedidentities.e3.b2;
package org.hibernate.orm.test.annotations.derivedidentities.e3.b3;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;

View File

@ -1,4 +1,4 @@
package org.hibernate.test.annotations.derivedidentities.e3.b3;
package org.hibernate.orm.test.annotations.derivedidentities.e3.b3;
import jakarta.persistence.*;

View File

@ -1,4 +1,4 @@
package org.hibernate.test.annotations.derivedidentities.e3.b3;
package org.hibernate.orm.test.annotations.derivedidentities.e3.b3;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;