From bc4804ab0936d243c61380b0e58d4dc7143e5691 Mon Sep 17 00:00:00 2001 From: Leon Schenk <989485+leonschenk@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:29:00 +0200 Subject: [PATCH] HHH-18675: Fix for testcase. If property is 'synthetic' then create no attribute for the jpa model. --- .../src/main/java/org/hibernate/mapping/Property.java | 2 +- .../hibernate/metamodel/internal/MetadataContext.java | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Property.java b/hibernate-core/src/main/java/org/hibernate/mapping/Property.java index d31c01799c..61860fd2d2 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Property.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Property.java @@ -477,7 +477,7 @@ public class Property implements Serializable, MetaAttributable { } public Property copy() { - final Property property = new Property(); + final Property property = this instanceof SyntheticProperty ? new SyntheticProperty() : new Property(); property.setName( getName() ); property.setValue( getValue() ); property.setCascade( getCascade() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java index 5498d8d4a2..4b6a5e28d0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java @@ -55,9 +55,9 @@ import java.util.Set; import java.util.function.BiFunction; import static java.util.Collections.unmodifiableMap; +import static java.util.Objects.nonNull; import static org.hibernate.metamodel.internal.InjectionHelper.injectField; - /** * Defines a context for storing information during the building of the {@link MappingMetamodelImpl}. *

@@ -274,9 +274,10 @@ public class MetadataContext { attribute = factoryFunction.apply( entityType, genericProperty ); if ( !property.isGeneric() ) { final PersistentAttribute concreteAttribute = factoryFunction.apply( entityType, property ); - @SuppressWarnings("unchecked") - final AttributeContainer attributeContainer = (AttributeContainer) entityType; - attributeContainer.getInFlightAccess().addConcreteGenericAttribute( concreteAttribute ); + if (nonNull(concreteAttribute)) { + @SuppressWarnings("unchecked") final AttributeContainer attributeContainer = (AttributeContainer) entityType; + attributeContainer.getInFlightAccess().addConcreteGenericAttribute(concreteAttribute); + } } } else {