Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-18384 @JoinColumnsOrFormulas broken #9273

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ private static List<PropertyData> collectClassElements(
//embeddable elements can have type defs
final PropertyContainer container =
new PropertyContainer( returnedClassOrElement, annotatedClass, propertyAccessor );
addElementsOfClass( classElements, container, context);
addElementsOfClass( classElements, container, context, 0 );
//add elements of the embeddable's mapped superclasses
ClassDetails subclass = returnedClassOrElement;
ClassDetails superClass;
Expand All @@ -659,7 +659,7 @@ private static List<PropertyData> collectClassElements(
annotatedClass,
propertyAccessor
);
addElementsOfClass( classElements, superContainer, context );
addElementsOfClass( classElements, superContainer, context, 0 );
if ( subclassToSuperclass != null ) {
subclassToSuperclass.put( subclass.getName(), superClass.getName() );
}
Expand Down Expand Up @@ -690,7 +690,7 @@ private static void collectSubclassElements(
assert put == null;
// collect property of subclass
final PropertyContainer superContainer = new PropertyContainer( subclass, superclass, propertyAccessor );
addElementsOfClass( classElements, superContainer, context );
addElementsOfClass( classElements, superContainer, context, 0 );
// recursively do that same for all subclasses
collectSubclassElements(
propertyAccessor,
Expand Down Expand Up @@ -764,7 +764,7 @@ private static List<PropertyData> collectBaseClassElements(
entityAtStake,
propertyAccessor
);
addElementsOfClass( baseClassElements, container, context );
addElementsOfClass( baseClassElements, container, context, 0 );
baseReturnedClassOrElement = baseReturnedClassOrElement.determineRawClass().getGenericSuperType();
}
return baseClassElements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,8 @@ private static PropertyData getUniqueIdPropertyFromBaseClass(
inferredData.getPropertyType(),
propertyAccessor
);
addElementsOfClass( baseClassElements, propContainer, context );
final int idPropertyCount = addElementsOfClass( baseClassElements, propContainer, context, 0 );
assert idPropertyCount == 1;
//Id properties are on top and there is only one
return baseClassElements.get( 0 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,11 @@ private ElementsToProcess getElementsToProcess() {
classDetails,
accessType
);
int currentIdPropertyCount = addElementsOfClass(
idPropertyCount = addElementsOfClass(
elements,
propertyContainer,
buildingContext
);
idPropertyCount += currentIdPropertyCount;
buildingContext,
idPropertyCount );
}

if ( idPropertyCount == 0 && !inheritanceState.hasParents() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,17 +583,17 @@ private void validateOptimisticLock(boolean excluded) {
/**
* @param elements List of {@link PropertyData} instances
* @param propertyContainer Metadata about a class and its properties
* @param idPropertyCounter number of id properties already present in list of {@link PropertyData} instances
*
* @return the number of id properties found while iterating the elements of
* {@code annotatedClass} using the determined access strategy
* @return total number of id properties found after iterating the elements of {@code annotatedClass}
* using the determined access strategy (starting from the provided {@code idPropertyCounter})
*/
static int addElementsOfClass(
List<PropertyData> elements,
PropertyContainer propertyContainer,
MetadataBuildingContext context) {
int idPropertyCounter = 0;
MetadataBuildingContext context, int idPropertyCounter) {
for ( MemberDetails property : propertyContainer.propertyIterator() ) {
idPropertyCounter += addProperty( propertyContainer, property, elements, context );
idPropertyCounter = addProperty( propertyContainer, property, elements, context, idPropertyCounter );
}
return idPropertyCounter;
}
Expand All @@ -602,20 +602,20 @@ private static int addProperty(
PropertyContainer propertyContainer,
MemberDetails property,
List<PropertyData> inFlightPropertyDataList,
MetadataBuildingContext context) {
MetadataBuildingContext context,
int idPropertyCounter) {
// see if inFlightPropertyDataList already contains a PropertyData for this name,
// and if so, skip it...
for ( PropertyData propertyData : inFlightPropertyDataList ) {
if ( propertyData.getPropertyName().equals( property.resolveAttributeName() ) ) {
checkIdProperty( property, propertyData );
// EARLY EXIT!!!
return 0;
return idPropertyCounter;
}
}

final ClassDetails declaringClass = propertyContainer.getDeclaringClass();
final TypeVariableScope ownerType = propertyContainer.getTypeAtStake();
int idPropertyCounter = 0;
final PropertyData propertyAnnotatedElement = new PropertyInferredData(
declaringClass,
ownerType,
Expand All @@ -628,7 +628,7 @@ private static int addProperty(
// before any association by Hibernate
final MemberDetails element = propertyAnnotatedElement.getAttributeMember();
if ( hasIdAnnotation( element ) ) {
inFlightPropertyDataList.add( 0, propertyAnnotatedElement );
inFlightPropertyDataList.add( idPropertyCounter, propertyAnnotatedElement );
handleIdProperty( propertyContainer, context, declaringClass, ownerType, element );
if ( hasToOneAnnotation( element ) ) {
context.getMetadataCollector()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.DomainModelScope;
import org.hibernate.testing.orm.junit.FailureExpected;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
Expand All @@ -40,7 +39,6 @@ void testAnnotations(DomainModelScope domainModelScope) {
@Test
@ServiceRegistry( settings = @Setting( name= MappingSettings.TRANSFORM_HBM_XML, value = "true" ) )
@DomainModel( xmlMappings = "mappings/models/hbm/joinformula/many-to-one-join-column-and-formula.xml" )
@FailureExpected( reason = "@JoinColumnsOrFormulas broken", jiraKey = "https://hibernate.atlassian.net/browse/HHH-18384" )
void testHbmXmlTransformed(DomainModelScope domainModelScope) {
verifyMapping( domainModelScope );
}
Expand Down