From 8eb4d8da0d84e528ba3d51ea39c269d149c4e80f Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 28 Aug 2024 23:19:52 +0200 Subject: [PATCH] HHH-18341 fix the issue simply by removing obsolete code also take the opportunity to "do" a todo Signed-off-by: Gavin King --- .../internal/AbstractPropertyHolder.java | 16 +++++------ .../boot/model/internal/AnnotatedColumn.java | 4 +-- .../model/internal/AnnotatedJoinColumns.java | 4 +-- .../boot/model/internal/CollectionBinder.java | 4 +-- .../source/spi/AbstractAttributeKey.java | 27 ++----------------- .../boot/model/source/AttributePathTest.java | 2 +- 6 files changed, 17 insertions(+), 40 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractPropertyHolder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractPropertyHolder.java index 0aedcf5f9f..06ce1c58b9 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractPropertyHolder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractPropertyHolder.java @@ -237,10 +237,10 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { public Column[] getOverriddenColumn(String propertyName) { final Column[] result = getExactOverriddenColumn( propertyName ); if ( result == null ) { - if ( propertyName.contains( ".collection&&element." ) ) { + if ( propertyName.contains( ".{element}." ) ) { //support for non map collections where no prefix is needed //TODO cache the underlying regexp - return getExactOverriddenColumn( propertyName.replace( ".collection&&element.", "." ) ); + return getExactOverriddenColumn( propertyName.replace( ".{element}.", "." ) ); } } return result; @@ -294,10 +294,10 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { @Override public JoinColumn[] getOverriddenJoinColumn(String propertyName) { final JoinColumn[] result = getExactOverriddenJoinColumn( propertyName ); - if ( result == null && propertyName.contains( ".collection&&element." ) ) { + if ( result == null && propertyName.contains( ".{element}." ) ) { //support for non map collections where no prefix is needed //TODO cache the underlying regexp - return getExactOverriddenJoinColumn( propertyName.replace( ".collection&&element.", "." ) ); + return getExactOverriddenJoinColumn( propertyName.replace( ".{element}.", "." ) ); } return result; } @@ -325,10 +325,10 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { @Override public ForeignKey getOverriddenForeignKey(String propertyName) { final ForeignKey result = getExactOverriddenForeignKey( propertyName ); - if ( result == null && propertyName.contains( ".collection&&element." ) ) { + if ( result == null && propertyName.contains( ".{element}." ) ) { //support for non map collections where no prefix is needed //TODO cache the underlying regexp - return getExactOverriddenForeignKey( propertyName.replace( ".collection&&element.", "." ) ); + return getExactOverriddenForeignKey( propertyName.replace( ".{element}.", "." ) ); } return result; } @@ -371,10 +371,10 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { */ public JoinTable getOverriddenJoinTable(String propertyName) { final JoinTable result = getExactOverriddenJoinTable( propertyName ); - if ( result == null && propertyName.contains( ".collection&&element." ) ) { + if ( result == null && propertyName.contains( ".{element}." ) ) { //support for non map collections where no prefix is needed //TODO cache the underlying regexp - return getExactOverriddenJoinTable( propertyName.replace( ".collection&&element.", "." ) ); + return getExactOverriddenJoinTable( propertyName.replace( ".{element}.", "." ) ); } return result; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java index b23f5108fb..9baff85253 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java @@ -400,9 +400,9 @@ public class AnnotatedColumn { ); // HHH-6005 magic - if ( implicitName.getText().contains( "_collection&&element_" ) ) { + if ( implicitName.getText().contains( "_{element}_" ) ) { implicitName = Identifier.toIdentifier( - implicitName.getText().replace( "_collection&&element_", "_" ), + implicitName.getText().replace( "_{element}_", "_" ), implicitName.isQuoted() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumns.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumns.java index ed89384bec..3d09e462bb 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumns.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumns.java @@ -445,9 +445,9 @@ public class AnnotatedJoinColumns extends AnnotatedColumns { new OwnedImplicitJoinColumnNameSource(referencedEntity, logicalTableName, logicalReferencedColumn) ); // HHH-11826 magic. See AnnotatedColumn and the HHH-6005 comments - if ( columnIdentifier.getText().contains( "_collection&&element_" ) ) { + if ( columnIdentifier.getText().contains( "_{element}_" ) ) { columnIdentifier = Identifier.toIdentifier( - columnIdentifier.getText().replace( "_collection&&element_", "_" ), + columnIdentifier.getText().replace( "_{element}_", "_" ), columnIdentifier.isQuoted() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java index 7891df0876..11bd6f71df 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java @@ -2490,8 +2490,8 @@ public abstract class CollectionBinder { return new PropertyPreloadedData( AccessType.PROPERTY, "element", elementClass ); } else { - //"collection&&element" is not a valid property name => placeholder - return new PropertyPreloadedData( AccessType.PROPERTY, "collection&&element", elementClass ); + //"{element}" is not a valid property name => placeholder + return new PropertyPreloadedData( AccessType.PROPERTY, "{element}", elementClass ); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/AbstractAttributeKey.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/AbstractAttributeKey.java index fe34492636..f675c7c30c 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/AbstractAttributeKey.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/AbstractAttributeKey.java @@ -6,22 +6,13 @@ */ package org.hibernate.boot.model.source.spi; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import org.hibernate.internal.util.StringHelper; /** * @author Steve Ebersole */ public abstract class AbstractAttributeKey { - // todo : replace this with "{element}" - private static final String COLLECTION_ELEMENT = "collection&&element"; - private static final String DOT_COLLECTION_ELEMENT = '.' + COLLECTION_ELEMENT; - private static final Pattern DOT_COLLECTION_ELEMENT_PATTERN = Pattern.compile( - DOT_COLLECTION_ELEMENT, - Pattern.LITERAL - ); + private static final String COLLECTION_ELEMENT = "{element}"; private final AbstractAttributeKey parent; private final String property; @@ -125,26 +116,12 @@ public abstract class AbstractAttributeKey { * Does this part represent a collection-element reference? * * @return {@code true} if the current property is a collection element - * marker ({@link #COLLECTION_ELEMENT} + * marker {@value #COLLECTION_ELEMENT} */ public boolean isCollectionElement() { return COLLECTION_ELEMENT.equals( property ); } - /** - * Does any part represent a collection-element reference? - * - * @return {@code true} if this part or any parent part is a collection element - * marker ({@link #COLLECTION_ELEMENT}. - */ - public boolean isPartOfCollectionElement() { - return fullPath.contains( DOT_COLLECTION_ELEMENT ); - } - - public String stripCollectionElementMarker() { - return DOT_COLLECTION_ELEMENT_PATTERN.matcher( fullPath ).replaceAll( Matcher.quoteReplacement( "" ) ); - } - @Override public String toString() { return getFullPath(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/model/source/AttributePathTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/model/source/AttributePathTest.java index ec1f61cd9f..3d4fb64aba 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/model/source/AttributePathTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/model/source/AttributePathTest.java @@ -21,7 +21,7 @@ public class AttributePathTest { @Test @TestForIssue(jiraKey = "HHH-10863") public void testCollectionElement() { - AttributePath attributePath = AttributePath.parse( "items.collection&&element.name" ); + AttributePath attributePath = AttributePath.parse( "items.{element}.name" ); assertFalse( attributePath.isCollectionElement() ); assertTrue( attributePath.getParent().isCollectionElement() );