diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/ColumnDefaults.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/ColumnDefaults.java index 65b9f1f397bc..6261c4300d3f 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/ColumnDefaults.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/ColumnDefaults.java @@ -20,5 +20,5 @@ interface ColumnDefaults { Boolean isInsertable(); - Boolean isUpdateable(); + Boolean isUpdatable(); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/ColumnDefaultsBasicImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/ColumnDefaultsBasicImpl.java index 4985dc438915..ffa4fea47c14 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/ColumnDefaultsBasicImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/ColumnDefaultsBasicImpl.java @@ -44,7 +44,7 @@ public Boolean isInsertable() { } @Override - public Boolean isUpdateable() { + public Boolean isUpdatable() { return Boolean.TRUE; } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/ColumnDefaultsInsertableNonUpdateableImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/ColumnDefaultsInsertableNonUpdateableImpl.java index 2ca9ba035e51..27274b9f1b02 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/ColumnDefaultsInsertableNonUpdateableImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/ColumnDefaultsInsertableNonUpdateableImpl.java @@ -44,7 +44,7 @@ public Boolean isInsertable() { } @Override - public Boolean isUpdateable() { + public Boolean isUpdatable() { return false; } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/ColumnDefaultsProperty.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/ColumnDefaultsProperty.java index 869a99a17576..1a75e9c992bd 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/ColumnDefaultsProperty.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/ColumnDefaultsProperty.java @@ -27,8 +27,8 @@ public Boolean isInsertable() { } @Override - public Boolean isUpdateable() { - return property.isUpdateable(); + public Boolean isUpdatable() { + return property.isUpdatable(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/HbmXmlTransformer.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/HbmXmlTransformer.java index b4b7fcc6698d..004bb79e331a 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/HbmXmlTransformer.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/HbmXmlTransformer.java @@ -1554,7 +1554,7 @@ public Boolean isInsertable() { } @Override - public Boolean isUpdateable() { + public Boolean isUpdatable() { return hbmProp.isUpdate(); } }, @@ -2797,7 +2797,7 @@ public Boolean isInsertable() { } @Override - public Boolean isUpdateable() { + public Boolean isUpdatable() { return true; } }, @@ -3027,7 +3027,7 @@ public Boolean isInsertable() { } @Override - public Boolean isUpdateable() { + public Boolean isUpdatable() { return true; } }, diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/TargetColumnAdapterJaxbColumn.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/TargetColumnAdapterJaxbColumn.java index f0c6694d1642..efb425cde17c 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/TargetColumnAdapterJaxbColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/TargetColumnAdapterJaxbColumn.java @@ -26,7 +26,7 @@ public TargetColumnAdapterJaxbColumn(JaxbColumnImpl jaxbColumn, ColumnDefaults c this.jaxbColumn.setNullable( columnDefaults.isNullable() ); this.jaxbColumn.setUnique( columnDefaults.isUnique() ); this.jaxbColumn.setInsertable( columnDefaults.isInsertable() ); - this.jaxbColumn.setUpdatable( columnDefaults.isUpdateable() ); + this.jaxbColumn.setUpdatable( columnDefaults.isUpdatable() ); } public JaxbColumnImpl getTargetColumn() { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/TargetColumnAdapterJaxbJoinColumn.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/TargetColumnAdapterJaxbJoinColumn.java index f65a369a5863..7d3ac10ccf0e 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/TargetColumnAdapterJaxbJoinColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/transform/TargetColumnAdapterJaxbJoinColumn.java @@ -21,7 +21,7 @@ public TargetColumnAdapterJaxbJoinColumn(JaxbJoinColumnImpl jaxbColumn, ColumnDe this.jaxbColumn.setNullable( columnDefaults.isNullable() ); this.jaxbColumn.setUnique( columnDefaults.isUnique() ); this.jaxbColumn.setInsertable( columnDefaults.isInsertable() ); - this.jaxbColumn.setUpdatable( columnDefaults.isUpdateable() ); + this.jaxbColumn.setUpdatable( columnDefaults.isUpdatable() ); } public JaxbJoinColumnImpl getTargetColumn() { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java index 8b349acb61ee..20b400f1cda7 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java @@ -22,7 +22,6 @@ import org.hibernate.annotations.OnDeleteAction; import org.hibernate.annotations.SqlFragmentAlias; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; -import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.PropertyData; import org.hibernate.internal.util.collections.ArrayHelper; @@ -74,7 +73,6 @@ import static org.hibernate.models.spi.TypeDetailsHelper.resolveRawClass; import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.EMBEDDED; import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.NOOP; -import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.interpret; /** * @author Emmanuel Bernard @@ -268,29 +266,23 @@ private static void registerSyntheticProperty( String propertyName, String syntheticPropertyName, MetadataBuildingContext context) { + final var collector = context.getMetadataCollector(); if ( value instanceof ToOne toOne ) { toOne.setReferencedPropertyName( syntheticPropertyName ); toOne.setReferenceToPrimaryKey( false ); - context.getMetadataCollector().addUniquePropertyReference( - ownerEntity.getEntityName(), - syntheticPropertyName - ); + collector.addUniquePropertyReference( ownerEntity.getEntityName(), syntheticPropertyName ); } else if ( value instanceof Collection collection ) { collection.setReferencedPropertyName( syntheticPropertyName ); //not unique because we could create a mtm wo association table - context.getMetadataCollector().addPropertyReference( - ownerEntity.getEntityName(), - syntheticPropertyName - ); + collector.addPropertyReference( ownerEntity.getEntityName(), syntheticPropertyName ); } else { throw new AssertionFailure( "Property ref on an unexpected Value type: " + value.getClass().getName() ); } final String associatedEntityName = associatedClass.getEntityName(); final String generatedName = inverse ? "inverse__" + associatedEntityName : associatedEntityName; - context.getMetadataCollector() - .addPropertyReferencedAssociation( generatedName, propertyName, syntheticPropertyName ); + collector.addPropertyReferencedAssociation( generatedName, propertyName, syntheticPropertyName ); } private static String syntheticPropertyName( @@ -310,13 +302,10 @@ private static String associationMessage(PersistentClass associatedEntity, Annot return "'" + associatedEntity.getEntityName() + "." + joinColumns.getPropertyName() + "'"; } else { - final PropertyHolder propertyHolder = joinColumns.getPropertyHolder(); - if ( propertyHolder != null ) { - return "'" + propertyHolder.getEntityName() + "." + joinColumns.getPropertyName() + "'"; - } - else { - return ""; - } + final var propertyHolder = joinColumns.getPropertyHolder(); + return propertyHolder != null + ? "'" + propertyHolder.getEntityName() + "." + joinColumns.getPropertyName() + "'" + : ""; } } @@ -332,6 +321,31 @@ private static Property makeSyntheticComponentProperty( MetadataBuildingContext context, String syntheticPropertyName, List properties) { + final Component embeddedComponent = + embeddedComponent( ownerEntity, persistentClassOrJoin, context, properties ); + final Property result = new SyntheticProperty(); + result.setName( syntheticPropertyName ); + result.setPersistentClass( ownerEntity ); + result.setUpdatable( false ); + result.setInsertable( false ); + result.setValue( embeddedComponent ); + result.setPropertyAccessorName( EMBEDDED.getExternalName() ); + if ( persistentClassOrJoin instanceof Join ) { + // the referenced column is in the joined table, add the synthetic property there + persistentClassOrJoin.addProperty( result ); + } + else { + ownerEntity.addProperty( result ); + } + embeddedComponent.createUniqueKey( context ); //make it unique + return result; + } + + private static Component embeddedComponent( + PersistentClass ownerEntity, + AttributeContainer persistentClassOrJoin, + MetadataBuildingContext context, + List properties) { final Component embeddedComponent; if ( persistentClassOrJoin instanceof PersistentClass persistentClass ) { embeddedComponent = new Component( context, persistentClass ); @@ -348,22 +362,7 @@ else if ( persistentClassOrJoin instanceof Join join ) { embeddedComponent.addProperty( cloneProperty( ownerEntity, context, property ) ); } embeddedComponent.sortProperties(); - final Property result = new SyntheticProperty(); - result.setName( syntheticPropertyName ); - result.setPersistentClass( ownerEntity ); - result.setUpdateable( false ); - result.setInsertable( false ); - result.setValue( embeddedComponent ); - result.setPropertyAccessorName( "embedded" ); - if ( persistentClassOrJoin instanceof Join ) { - // the referenced column is in the joined table, add the synthetic property there - persistentClassOrJoin.addProperty( result ); - } - else { - ownerEntity.addProperty( result ); - } - embeddedComponent.createUniqueKey( context ); //make it unique - return result; + return embeddedComponent; } /** @@ -384,7 +383,7 @@ private static Property cloneProperty(PersistentClass ownerEntity, MetadataBuild final Property result = new SyntheticProperty(); result.setName( property.getName() ); result.setPersistentClass( ownerEntity ); - result.setUpdateable( false ); + result.setUpdatable( false ); result.setInsertable( false ); result.setValue(copy); result.setPropertyAccessorName( property.getPropertyAccessorName() ); @@ -393,7 +392,7 @@ private static Property cloneProperty(PersistentClass ownerEntity, MetadataBuild else { final Property clone = shallowCopy( property ); clone.setInsertable( false ); - clone.setUpdateable( false ); + clone.setUpdatable( false ); clone.setNaturalIdentifier( false ); clone.setValueGeneratorCreator( property.getValueGeneratorCreator() ); return clone; @@ -416,7 +415,7 @@ public static Property shallowCopy(Property property) { clone.setPersistentClass( property.getPersistentClass() ); clone.setPropertyAccessorName( property.getPropertyAccessorName() ); clone.setSelectable( property.isSelectable() ); - clone.setUpdateable( property.isUpdateable() ); + clone.setUpdatable( property.isUpdatable() ); clone.setValue( property.getValue() ); return clone; } @@ -433,10 +432,10 @@ private static List findPropertiesByColumns( // specified by the @JoinColumn annotations. final List orderedColumns = new ArrayList<>( columns.getJoinColumns().size() ); final Map> columnsToProperty = new HashMap<>(); - final InFlightMetadataCollector collector = context.getMetadataCollector(); - for ( AnnotatedJoinColumn joinColumn : columns.getJoinColumns() ) { + final var collector = context.getMetadataCollector(); + for ( var joinColumn : columns.getJoinColumns() ) { if ( joinColumn.isReferenceImplicit() ) { - throw new AnnotationException("Association " + associationMessage( associatedEntity, columns ) + throw new AnnotationException( "Association " + associationMessage( associatedEntity, columns ) + " has a '@JoinColumn' which does not specify the 'referencedColumnName'" + " (when an association has multiple '@JoinColumn's, they must each specify their 'referencedColumnName')"); } @@ -554,28 +553,28 @@ else if ( orderedProperties.contains( property ) ) { } private static void matchColumnsByProperty(Property property, Map> columnsToProperty) { - if ( property != null - && NOOP != interpret( property.getPropertyAccessorName() ) - && EMBEDDED != interpret( property.getPropertyAccessorName() ) ) { - //TODO: we can't return subproperties because the caller - // needs top level properties, but this results in - // a limitation where I need to be referencing all - // columns of an embeddable instead of just some -// if ( property.isComposite() ) { -// for ( Property sp : ( (Component) property.getValue() ).getProperties() ) { -// matchColumnsByProperty( sp, columnsToProperty ); + if ( property != null ) { + final String propertyAccessorName = property.getPropertyAccessorName(); + if ( !NOOP.getExternalName().equals( propertyAccessorName ) + && !EMBEDDED.getExternalName().equals( propertyAccessorName ) ) { + //TODO: we can't return subproperties because the caller + // needs top level properties, but this results in + // a limitation where I need to be referencing all + // columns of an embeddable instead of just some +// if ( property.isComposite() ) { +// for ( Property sp : ( (Component) property.getValue() ).getProperties() ) { +// matchColumnsByProperty( sp, columnsToProperty ); +// } // } -// } -// else { - for ( Selectable selectable : property.getSelectables() ) { - //can be a Formula, so we don't cast - //noinspection SuspiciousMethodCalls - if ( columnsToProperty.containsKey( selectable ) ) { - //noinspection SuspiciousMethodCalls - columnsToProperty.get( selectable ).add( property ); +// else { + for ( Selectable selectable : property.getSelectables() ) { + if ( selectable instanceof Column column + && columnsToProperty.containsKey( column ) ) { + columnsToProperty.get( column ).add( property ); + } } +// } } -// } } } @@ -597,9 +596,9 @@ public static Property findPropertyByName(PersistentClass associatedClass, Strin property = idProperty; propertyName = propertyName.substring( idName.length() + 1 ); } - final StringTokenizer tokens = new StringTokenizer( propertyName, ".", false ); - while ( tokens.hasMoreElements() ) { - String element = (String) tokens.nextElement(); + final var tokens = new StringTokenizer( propertyName, ".", false ); + while ( tokens.hasMoreTokens() ) { + final String element = tokens.nextToken(); if ( property == null ) { property = associatedClass.getProperty( element ); } @@ -614,13 +613,13 @@ public static Property findPropertyByName(PersistentClass associatedClass, Strin } catch ( MappingException e ) { try { - //if we do not find it try to check the identifier mapper + // if we do not find it, try to check the identifier mapper if ( associatedClass.getIdentifierMapper() == null ) { return null; } - final StringTokenizer tokens = new StringTokenizer( propertyName, ".", false ); - while ( tokens.hasMoreElements() ) { - final String element = (String) tokens.nextElement(); + final var tokens = new StringTokenizer( propertyName, ".", false ); + while ( tokens.hasMoreTokens() ) { + final String element = tokens.nextToken(); if ( property == null ) { property = associatedClass.getIdentifierMapper().getProperty( element ); } @@ -650,9 +649,9 @@ public static Property findPropertyByName(Component component, String propertyNa return null; } else { - final StringTokenizer tokens = new StringTokenizer( propertyName, ".", false ); - while ( tokens.hasMoreElements() ) { - final String element = (String) tokens.nextElement(); + final var tokens = new StringTokenizer( propertyName, ".", false ); + while ( tokens.hasMoreTokens() ) { + final String element = tokens.nextToken(); if ( property == null ) { property = component.getProperty( element ); } @@ -667,13 +666,13 @@ public static Property findPropertyByName(Component component, String propertyNa } catch (MappingException e) { try { - //if we do not find it try to check the identifier mapper + // if we do not find it, try to check the identifier mapper if ( component.getOwner().getIdentifierMapper() == null ) { return null; } - final StringTokenizer tokens = new StringTokenizer( propertyName, ".", false ); - while ( tokens.hasMoreElements() ) { - final String element = (String) tokens.nextElement(); + final var tokens = new StringTokenizer( propertyName, ".", false ); + while ( tokens.hasMoreTokens() ) { + final String element = tokens.nextToken(); if ( property == null ) { property = component.getOwner().getIdentifierMapper().getProperty( element ); } @@ -722,7 +721,7 @@ public static AttributeContainer findColumnOwner( PersistentClass persistentClass, String columnName, MetadataBuildingContext context) { - final InFlightMetadataCollector metadataCollector = context.getMetadataCollector(); + final var metadataCollector = context.getMetadataCollector(); PersistentClass current = persistentClass; while ( current != null ) { try { @@ -916,8 +915,7 @@ public static EnumSet aggregateCascadeTypes( Cascade cascadeAnnotation, boolean orphanRemoval, MetadataBuildingContext context) { - final EnumSet cascades = - convertToHibernateCascadeType( cascadeTypes ); + final var cascades = convertToHibernateCascadeType( cascadeTypes ); final CascadeType[] hibernateCascades = cascadeAnnotation == null ? null @@ -937,7 +935,7 @@ public static EnumSet aggregateCascadeTypes( } private static EnumSet convertToHibernateCascadeType(jakarta.persistence.CascadeType[] cascades) { - final EnumSet cascadeTypes = EnumSet.noneOf( CascadeType.class ); + final var cascadeTypes = EnumSet.noneOf( CascadeType.class ); if ( cascades != null ) { for ( jakarta.persistence.CascadeType cascade: cascades ) { cascadeTypes.add( convertCascadeType( cascade ) ); @@ -958,8 +956,8 @@ private static CascadeType convertCascadeType(jakarta.persistence.CascadeType ca } public static String renderCascadeTypeList(EnumSet cascadeTypes) { - final StringBuilder cascade = new StringBuilder(); - for ( CascadeType cascadeType : cascadeTypes ) { + final var cascade = new StringBuilder(); + for ( var cascadeType : cascadeTypes ) { cascade.append( "," ); cascade.append( switch ( cascadeType ) { case ALL -> "all"; @@ -1076,14 +1074,12 @@ public static A extractFromPackage( // where context.getMetadataCollector() can cache some of this - either the annotations themselves // or even just the XPackage resolutions - final String declaringClassName = classDetails.getName(); - final String packageName = qualifier( declaringClassName ); + final String packageName = qualifier( classDetails.getName() ); if ( isEmpty( packageName ) ) { return null; } else { - final ModelsContext modelsContext = - context.getBootstrapContext().getModelsContext(); + final var modelsContext = context.getBootstrapContext().getModelsContext(); try { return modelsContext.getClassDetailsRegistry() .resolveClassDetails( packageName + ".package-info" ) 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 fdc4aecd0f4d..229646b5bf95 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 @@ -99,6 +99,7 @@ import static org.hibernate.boot.model.internal.AnnotatedColumn.buildFormulaFromAnnotation; import static org.hibernate.boot.model.internal.AnnotatedJoinColumns.buildJoinColumnsWithDefaultColumnSuffix; import static org.hibernate.boot.model.internal.AnnotatedJoinColumns.buildJoinTableJoinColumns; +import static org.hibernate.boot.model.internal.BasicValueBinder.Kind.COLLECTION_ELEMENT; import static org.hibernate.boot.model.internal.BinderHelper.aggregateCascadeTypes; import static org.hibernate.boot.model.internal.BinderHelper.buildAnyValue; import static org.hibernate.boot.model.internal.BinderHelper.checkMappedByType; @@ -123,6 +124,7 @@ import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty; import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty; import static org.hibernate.mapping.MappingHelper.createUserTypeBean; +import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.BASIC; /** * Base class for stateful binders responsible for producing mapping model objects of type {@link Collection}. @@ -1628,7 +1630,7 @@ private void createOneToManyBackref(org.hibernate.mapping.OneToMany oneToMany) { + "Backref"; backref.setName( backrefName ); backref.setOptional( true ); - backref.setUpdateable( false); + backref.setUpdatable( false); backref.setSelectable( false ); backref.setCollectionRole( getRole() ); backref.setEntityName( collection.getOwner().getEntityName() ); @@ -2115,9 +2117,7 @@ private void handleElementCollection(TypeDetails elementType, String hqlOrderBy) // 'property' is the collection XProperty final boolean isPrimitive = isPrimitive( elementType.getName() ); - final ClassDetails elementClass = isPrimitive - ? null - : elementType.determineRawClass(); + final ClassDetails elementClass = isPrimitive ? null : elementType.determineRawClass(); final AnnotatedClassType classType = annotatedElementType( isEmbedded, isPrimitive, property, elementClass ); if ( !isPrimitive ) { propertyHolder.startingProperty( property ); @@ -2126,8 +2126,7 @@ private void handleElementCollection(TypeDetails elementType, String hqlOrderBy) final CollectionPropertyHolder holder = buildPropertyHolder( collection, getRole(), elementClass, property, propertyHolder, buildingContext ); - final Class> compositeUserType = - resolveCompositeUserType( property, elementClass, buildingContext ); + final var compositeUserType = resolveCompositeUserType( property, elementClass, buildingContext ); final boolean isComposite = classType == EMBEDDABLE || compositeUserType != null; holder.prepare( property, isComposite ); @@ -2144,8 +2143,7 @@ private void handleCollectionElement( String hqlOrderBy, ClassDetails elementClass, CollectionPropertyHolder holder) { - final BasicValueBinder elementBinder = - new BasicValueBinder( BasicValueBinder.Kind.COLLECTION_ELEMENT, buildingContext ); + final var elementBinder = new BasicValueBinder( COLLECTION_ELEMENT, buildingContext ); elementBinder.setReturnedClassName( elementType.getName() ); final AnnotatedColumns actualColumns = createElementColumnsIfNecessary( collection, @@ -2177,10 +2175,10 @@ private void handleCompositeCollectionElement( Class> compositeUserType) { //TODO be smart with isNullable final AccessType accessType = accessType( property, collection.getOwner() ); - // We create a new entity binder here because it is needed for processing the embeddable + // We create a new entity binder here because it's needed for processing the embeddable // Since this is an element collection, there is no real entity binder though, // so we just create an "empty shell" for the purpose of avoiding null checks in the fillEmbeddable() method etc. - final EntityBinder entityBinder = new EntityBinder( buildingContext ); + final var entityBinder = new EntityBinder( buildingContext ); // Copy over the access type that we resolve for the element collection, // so that nested components use the same access type. This fixes HHH-15966 entityBinder.setPropertyAccessType( accessType ); @@ -2216,20 +2214,27 @@ static AccessType accessType(MemberDetails property, PersistentClass owner) { ? AccessType.PROPERTY : AccessType.FIELD; } - else if ( owner.getIdentifierProperty() != null ) { - // use the access for the owning entity's id attribute, if one - return owner.getIdentifierProperty().getPropertyAccessorName().equals( "property" ) - ? AccessType.PROPERTY - : AccessType.FIELD; - } - else if ( owner.getIdentifierMapper() != null && owner.getIdentifierMapper().getPropertySpan() > 0 ) { - // use the access for the owning entity's "id mapper", if one - return owner.getIdentifierMapper().getProperties().get(0).getPropertyAccessorName().equals( "property" ) - ? AccessType.PROPERTY - : AccessType.FIELD; - } else { - throw new AssertionFailure( "Unable to guess collection property accessor name" ); + final Property identifierProperty = owner.getIdentifierProperty(); + if ( identifierProperty != null ) { + // use the access for the owning entity's id attribute, if one + return identifierProperty.getPropertyAccessorName().equals( BASIC.getExternalName() ) + ? AccessType.PROPERTY + : AccessType.FIELD; + } + else { + final Component identifierMapper = owner.getIdentifierMapper(); + if ( identifierMapper != null && identifierMapper.getPropertySpan() > 0 ) { + // use the access for the owning entity's "id mapper" + final Property first = identifierMapper.getProperties().get( 0 ); + return first.getPropertyAccessorName().equals( BASIC.getExternalName() ) + ? AccessType.PROPERTY + : AccessType.FIELD; + } + else { + throw new AssertionFailure( "Unable to guess collection property accessor name" ); + } + } } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java index bf13a4c15377..52a057a8155d 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java @@ -38,13 +38,11 @@ import org.hibernate.boot.model.relational.QualifiedTableName; import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.JpaAnnotations; -import org.hibernate.boot.models.annotations.internal.CacheAnnotation; import org.hibernate.boot.models.annotations.spi.CustomSqlDetails; import org.hibernate.boot.models.annotations.spi.DialectOverrider; import org.hibernate.boot.spi.AccessType; import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.MetadataBuildingContext; -import org.hibernate.boot.spi.MetadataBuildingOptions; import org.hibernate.boot.spi.PropertyData; import org.hibernate.cfg.AvailableSettings; import org.hibernate.dialect.Dialect; @@ -60,7 +58,6 @@ import org.hibernate.mapping.DependantValue; import org.hibernate.mapping.Join; import org.hibernate.mapping.JoinedSubclass; -import org.hibernate.mapping.MappedSuperclass; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.mapping.RootClass; @@ -75,7 +72,6 @@ import org.hibernate.models.internal.ClassTypeDetailsImpl; import org.hibernate.models.spi.AnnotationTarget; import org.hibernate.models.spi.ClassDetails; -import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.MemberDetails; import org.hibernate.models.spi.ModelsContext; import org.hibernate.models.spi.TypeDetails; @@ -83,16 +79,15 @@ import java.lang.annotation.Annotation; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import static jakarta.persistence.InheritanceType.SINGLE_TABLE; +import static java.util.Collections.addAll; import static org.hibernate.boot.model.internal.AnnotatedClassType.MAPPED_SUPERCLASS; import static org.hibernate.boot.model.internal.AnnotatedDiscriminatorColumn.DEFAULT_DISCRIMINATOR_COLUMN_NAME; import static org.hibernate.boot.model.internal.AnnotatedDiscriminatorColumn.buildDiscriminatorColumn; @@ -121,10 +116,12 @@ import static org.hibernate.internal.util.StringHelper.isBlank; import static org.hibernate.internal.util.StringHelper.isNotBlank; import static org.hibernate.internal.util.StringHelper.nullIfEmpty; +import static org.hibernate.internal.util.StringHelper.root; import static org.hibernate.internal.util.StringHelper.unqualify; import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty; import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty; import static org.hibernate.jpa.event.internal.CallbackDefinitionResolver.resolveLifecycleCallbacks; +import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.EMBEDDED; /** @@ -183,17 +180,17 @@ public static void bindEntityClass( LOG.trace( "Binding entity with annotated class: " + clazzToProcess.getName() ); } - final InFlightMetadataCollector collector = context.getMetadataCollector(); - final ModelsContext modelsContext = context.getBootstrapContext().getModelsContext(); + final var collector = context.getMetadataCollector(); + final var modelsContext = context.getBootstrapContext().getModelsContext(); //TODO: be more strict with secondary table allowance (not for ids, not for secondary table join columns etc) - final InheritanceState inheritanceState = inheritanceStates.get( clazzToProcess ); - final PersistentClass superEntity = getSuperEntity( clazzToProcess, inheritanceStates, context, inheritanceState ); - final PersistentClass persistentClass = makePersistentClass( inheritanceState, superEntity, context ); + final var inheritanceState = inheritanceStates.get( clazzToProcess ); + final var superEntity = getSuperEntity( clazzToProcess, inheritanceStates, context, inheritanceState ); + final var persistentClass = makePersistentClass( inheritanceState, superEntity, context ); checkOverrides( clazzToProcess, superEntity, modelsContext ); - final EntityBinder entityBinder = new EntityBinder( clazzToProcess, persistentClass, context ); + final var entityBinder = new EntityBinder( clazzToProcess, persistentClass, context ); entityBinder.bindEntity(); entityBinder.bindSubselect(); // has to happen before table binding entityBinder.bindTables( inheritanceState, superEntity ); @@ -201,7 +198,7 @@ public static void bindEntityClass( entityBinder.bindSynchronize(); entityBinder.bindFilters(); entityBinder.handleCheckConstraints(); - final PropertyHolder holder = buildPropertyHolder( + final var holder = buildPropertyHolder( clazzToProcess, persistentClass, entityBinder, @@ -263,7 +260,7 @@ private static void checkOverrides(ClassDetails clazzToProcess, PersistentClass */ private static void checkOverride( PersistentClass superEntity, String name, ClassDetails clazzToProcess, Class overrideClass) { - if ( superEntity.hasProperty( StringHelper.root(name) ) ) { + if ( superEntity.hasProperty( root(name) ) ) { throw new AnnotationException("Property '" + name + "' is inherited from entity '" + superEntity.getEntityName() + "' and may not be overridden using '@" + overrideClass.getSimpleName() @@ -290,7 +287,7 @@ private static void bindSoftDelete( } private static SoftDelete extractSoftDelete(ClassDetails classDetails, MetadataBuildingContext context) { - final ModelsContext modelsContext = context.getBootstrapContext().getModelsContext(); + final var modelsContext = context.getBootstrapContext().getModelsContext(); final SoftDelete fromClass = classDetails.getAnnotationUsage( SoftDelete.class, modelsContext ); if ( fromClass != null ) { return fromClass; @@ -303,7 +300,6 @@ private static SoftDelete extractSoftDelete(ClassDetails classDetails, MetadataB && classToCheck.hasAnnotationUsage( jakarta.persistence.MappedSuperclass.class, modelsContext ) ) { return fromSuper; } - classToCheck = classToCheck.getSuperClass(); } @@ -339,15 +335,14 @@ private void addCheckToEntity(Check check) { } private void callTypeBinders(PersistentClass persistentClass) { - final List metaAnnotatedList = - annotatedClass.getMetaAnnotated( TypeBinderType.class, modelsContext() ); + final var metaAnnotatedList = annotatedClass.getMetaAnnotated( TypeBinderType.class, modelsContext() ); for ( Annotation metaAnnotated : metaAnnotatedList ) { applyTypeBinder( metaAnnotated, persistentClass ); } } private void applyTypeBinder(Annotation containingAnnotation, PersistentClass persistentClass) { - final Class> binderClass = + final var binderClass = containingAnnotation.annotationType() .getAnnotation( TypeBinderType.class ) .binder(); @@ -367,7 +362,7 @@ private void handleIdentifier( PropertyHolder propertyHolder, Map inheritanceStates, InheritanceState inheritanceState) { - final ElementsToProcess elementsToProcess = inheritanceState.postProcess( persistentClass, this ); + final var elementsToProcess = inheritanceState.postProcess( persistentClass, this ); final Set idPropertiesIfIdClass = handleIdClass( persistentClass, inheritanceState, @@ -388,8 +383,8 @@ private void handleIdentifier( } private void processComplementaryTableDefinitions() { - final jakarta.persistence.Table jpaTableUsage = - annotatedClass.getAnnotationUsage( jakarta.persistence.Table.class, modelsContext() ); + final var models = modelsContext(); + final var jpaTableUsage = annotatedClass.getAnnotationUsage( jakarta.persistence.Table.class, models ); if ( jpaTableUsage != null ) { final Table table = persistentClass.getTable(); TableBinder.addJpaIndexes( table, jpaTableUsage.indexes(), context ); @@ -398,14 +393,11 @@ private void processComplementaryTableDefinitions() { TableBinder.addTableOptions( table, jpaTableUsage.options() ); } - final InFlightMetadataCollector.EntityTableXref entityTableXref = - getMetadataCollector().getEntityTableXref( persistentClass.getEntityName() ); - - annotatedClass.forEachAnnotationUsage( jakarta.persistence.SecondaryTable.class, modelsContext(), (usage) -> { + final var entityTableXref = getMetadataCollector().getEntityTableXref( persistentClass.getEntityName() ); + annotatedClass.forEachAnnotationUsage( jakarta.persistence.SecondaryTable.class, models, (usage) -> { final Identifier secondaryTableLogicalName = toIdentifier( usage.name() ); final Table table = entityTableXref.resolveTable( secondaryTableLogicalName ); assert table != null; - TableBinder.addJpaIndexes( table, usage.indexes(), context ); } ); } @@ -444,9 +436,9 @@ private boolean mapAsIdClass( // We are looking for @IdClass // In general we map the id class as identifier using the mapping metadata of the main entity's // properties and create an identifier mapper containing the id properties of the main entity - final ClassDetails classWithIdClass = inheritanceState.getClassWithIdClass( false ); + final var classWithIdClass = inheritanceState.getClassWithIdClass( false ); if ( classWithIdClass != null ) { - final ClassDetails compositeClass = idClassDetails( inheritanceState, classWithIdClass ); + final var compositeClass = idClassDetails( inheritanceState, classWithIdClass ); return compositeClass != null && mapAsIdClass( inheritanceStates, persistentClass, propertyHolder, elementsToProcess, idPropertiesIfIdClass, context, compositeClass, classWithIdClass ); @@ -523,7 +515,7 @@ private boolean mapAsIdClass( private ClassDetails idClassDetails(InheritanceState inheritanceState, ClassDetails classWithIdClass) { final IdClass idClassAnn = classWithIdClass.getDirectAnnotationUsage( IdClass.class ); - final ClassDetailsRegistry classDetailsRegistry = modelsContext().getClassDetailsRegistry(); + final var classDetailsRegistry = modelsContext().getClassDetailsRegistry(); if ( idClassAnn == null ) { try { // look for an Id class generated by Hibernate Processor as an inner class of static metamodel @@ -569,9 +561,9 @@ private Component createMapperProperty( ); final Property mapperProperty = new SyntheticProperty(); mapperProperty.setName( NavigablePath.IDENTIFIER_MAPPER_PROPERTY ); - mapperProperty.setUpdateable( false ); + mapperProperty.setUpdatable( false ); mapperProperty.setInsertable( false ); - mapperProperty.setPropertyAccessorName( "embedded" ); + mapperProperty.setPropertyAccessorName( EMBEDDED.getExternalName() ); mapperProperty.setValue( mapper ); persistentClass.addProperty( mapperProperty); return mapper; @@ -612,7 +604,7 @@ private Component createMapper( persistentClass.setIdentifierMapper( mapper ); // If id definition is on a mapped superclass, update the mapping - final MappedSuperclass superclass = getMappedSuperclassOrNull( classWithIdClass, inheritanceStates, context ); + final var superclass = getMappedSuperclassOrNull( classWithIdClass, inheritanceStates, context ); if ( superclass != null ) { superclass.setDeclaredIdentifierMapper( mapper ); } @@ -629,7 +621,7 @@ private static PropertyData getUniqueIdPropertyFromBaseClass( AccessType propertyAccessor, MetadataBuildingContext context) { final List baseClassElements = new ArrayList<>(); - final PropertyContainer propContainer = + final var propContainer = new PropertyContainer( baseInferredData.getClassOrElementType().determineRawClass(), inferredData.getPropertyType(), propertyAccessor ); final int idPropertyCount = addElementsOfClass( baseClassElements, propContainer, context, 0 ); @@ -662,8 +654,7 @@ private boolean isIdClassPrimaryKeyOfAssociatedEntity( } else { - final IdClass idClass = - associatedClassWithIdClass.getAnnotationUsage( IdClass.class, modelsContext() ); + final IdClass idClass = associatedClassWithIdClass.getAnnotationUsage( IdClass.class, modelsContext() ); return compositeClass.getName().equals( idClass.value().getName() ); } } @@ -682,7 +673,7 @@ private Component bindIdClass( propertyHolder.setInIdClass( true ); // Fill simple value and property since and Id is a property - final PersistentClass persistentClass = propertyHolder.getPersistentClass(); + final var persistentClass = propertyHolder.getPersistentClass(); if ( !( persistentClass instanceof RootClass rootClass ) ) { throw new AnnotationException( "Entity '" + persistentClass.getEntityName() + "' is a subclass in an entity inheritance hierarchy and may not redefine the identifier of the root entity" ); @@ -732,7 +723,7 @@ private void handleClassTable(InheritanceState inheritanceState, PersistentClass final String table; final String catalog; final UniqueConstraint[] uniqueConstraints; - final jakarta.persistence.Table tableAnnotation = + final var tableAnnotation = annotatedClass.getAnnotationUsage( jakarta.persistence.Table.class, modelsContext() ); if ( tableAnnotation != null ) { table = tableAnnotation.name(); @@ -770,8 +761,9 @@ private void createTable( String table, String catalog, UniqueConstraint[] uniqueConstraints) { - final RowId rowId = annotatedClass.getAnnotationUsage( RowId.class, modelsContext() ); - final View view = annotatedClass.getAnnotationUsage( View.class, modelsContext() ); + final var models = modelsContext(); + final RowId rowId = annotatedClass.getAnnotationUsage( RowId.class, models ); + final View view = annotatedClass.getAnnotationUsage( View.class, models ); bindTable( schema, catalog, @@ -819,7 +811,7 @@ private void singleTableInheritance(InheritanceState inheritanceState, PropertyH processSingleTableDiscriminatorProperties( inheritanceState ); // todo : sucks that this is separate from RootClass distinction if ( !inheritanceState.hasParents() ) { - final RootClass rootClass = (RootClass) persistentClass; + final var rootClass = (RootClass) persistentClass; if ( inheritanceState.hasSiblings() || discriminatorColumn != null && !discriminatorColumn.isImplicit() ) { bindDiscriminatorColumnToRootPersistentClass( rootClass, discriminatorColumn, holder ); @@ -832,10 +824,9 @@ private void singleTableInheritance(InheritanceState inheritanceState, PropertyH private void joinedInheritance(InheritanceState state, PersistentClass superEntity, PropertyHolder holder) { if ( state.hasParents() ) { - final AnnotatedJoinColumns joinColumns = subclassJoinColumns( annotatedClass, superEntity, context ); - final JoinedSubclass joinedSubclass = (JoinedSubclass) persistentClass; - final DependantValue key = - new DependantValue( context, joinedSubclass.getTable(), joinedSubclass.getIdentifier() ); + final var joinColumns = subclassJoinColumns( annotatedClass, superEntity, context ); + final var joinedSubclass = (JoinedSubclass) persistentClass; + final var key = new DependantValue( context, joinedSubclass.getTable(), joinedSubclass.getIdentifier() ); joinedSubclass.setKey( key ); handleForeignKeys( annotatedClass, context, key ); final OnDelete onDelete = annotatedClass.getAnnotationUsage( OnDelete.class, modelsContext() ); @@ -846,9 +837,9 @@ private void joinedInheritance(InheritanceState state, PersistentClass superEnti metadataCollector.addSecondPass( new CreateKeySecondPass( joinedSubclass ) ); } - final AnnotatedDiscriminatorColumn discriminatorColumn = processJoinedDiscriminatorProperties( state ); + final var discriminatorColumn = processJoinedDiscriminatorProperties( state ); if ( !state.hasParents() ) { // todo : sucks that this is separate from RootClass distinction - final RootClass rootClass = (RootClass) persistentClass; + final var rootClass = (RootClass) persistentClass; // the class we're processing is the root of the hierarchy, so // let's see if we had a discriminator column (it's perfectly // valid for joined inheritance to not have a discriminator) @@ -923,7 +914,7 @@ private void bindDiscriminatorColumnToRootPersistentClass( if ( discriminatorColumn == null ) { throw new AssertionFailure( "discriminator column should have been built" ); } - final AnnotatedColumns columns = new AnnotatedColumns(); + final var columns = new AnnotatedColumns(); columns.setPropertyHolder( holder ); columns.setBuildingContext( context ); columns.setJoins( secondaryTables ); @@ -931,7 +922,7 @@ private void bindDiscriminatorColumnToRootPersistentClass( // discriminatorColumn.setPropertyHolder( holder ); discriminatorColumn.setParent( columns ); - final BasicValue discriminatorColumnBinding = new BasicValue( context, rootClass.getTable() ); + final var discriminatorColumnBinding = new BasicValue( context, rootClass.getTable() ); rootClass.setDiscriminator( discriminatorColumnBinding ); discriminatorColumn.linkWithValue( discriminatorColumnBinding ); discriminatorColumnBinding.setTypeName( discriminatorColumn.getDiscriminatorTypeName() ); @@ -1009,7 +1000,7 @@ private AnnotatedDiscriminatorColumn processJoinedDiscriminatorProperties(Inheri * */ private boolean useDiscriminatorColumnForJoined(DiscriminatorColumn discriminatorColumn) { - final MetadataBuildingOptions buildingOptions = context.getBuildingOptions(); + final var buildingOptions = context.getBuildingOptions(); if ( discriminatorColumn != null ) { final boolean ignore = buildingOptions.ignoreExplicitDiscriminatorsForJoinedInheritance(); if ( ignore ) { @@ -1091,7 +1082,7 @@ else if ( !missingEntityProperties.isEmpty() ) { } private static String getMissingPropertiesString(Set propertyNames) { - final StringBuilder missingProperties = new StringBuilder(); + final var missingProperties = new StringBuilder(); for ( String propertyName : propertyNames ) { if ( !missingProperties.isEmpty() ) { missingProperties.append( ", " ); @@ -1123,7 +1114,7 @@ private static AnnotatedJoinColumns subclassJoinColumns( PersistentClass superEntity, MetadataBuildingContext context) { //@Inheritance(JOINED) subclass need to link back to the super entity - final AnnotatedJoinColumns joinColumns = new AnnotatedJoinColumns(); + final var joinColumns = new AnnotatedJoinColumns(); joinColumns.setBuildingContext( context ); final ModelsContext modelsContext = context.getBootstrapContext().getModelsContext(); @@ -1320,7 +1311,7 @@ private boolean isMutable() { private void registerImportName() { try { - final InFlightMetadataCollector metadataCollector = getMetadataCollector(); + final var metadataCollector = getMetadataCollector(); metadataCollector.addImport( name, persistentClass.getEntityName() ); final String entityName = persistentClass.getEntityName(); if ( !entityName.equals( name ) ) { @@ -1333,7 +1324,7 @@ private void registerImportName() { } private void bindRootEntity() { - final RootClass rootClass = (RootClass) persistentClass; + final var rootClass = (RootClass) persistentClass; rootClass.setMutable( isMutable() ); if ( isNotBlank( where ) ) { rootClass.setWhere( where ); @@ -1491,7 +1482,7 @@ private String getDefaultFilterCondition(String filterName) { private void bindSynchronize() { final Synchronize synchronize = annotatedClass.getAnnotationUsage( Synchronize.class, modelsContext() ); if ( synchronize != null ) { - final JdbcEnvironment jdbcEnvironment = getMetadataCollector().getDatabase().getJdbcEnvironment(); + final var jdbcEnvironment = getMetadataCollector().getDatabase().getJdbcEnvironment(); final boolean logical = synchronize.logical(); for ( String tableName : synchronize.value() ) { final String physicalName = logical ? toPhysicalName( jdbcEnvironment, tableName ) : tableName; @@ -1501,8 +1492,7 @@ private void bindSynchronize() { } private String toPhysicalName(JdbcEnvironment jdbcEnvironment, String logicalName) { - final Identifier identifier = - jdbcEnvironment.getIdentifierHelper().toIdentifier( logicalName ); + final var identifier = jdbcEnvironment.getIdentifierHelper().toIdentifier( logicalName ); return context.getBuildingOptions().getPhysicalNamingStrategy() .toPhysicalTableName( identifier, jdbcEnvironment ) .render( jdbcEnvironment.getDialect() ); @@ -1606,7 +1596,7 @@ private void bindSqlRestriction() { } private SQLRestriction extractSQLRestriction(ClassDetails classDetails) { - final ModelsContext modelsContext = modelsContext(); + final var modelsContext = modelsContext(); final SQLRestriction fromClass = getOverridableAnnotation( classDetails, SQLRestriction.class, context ); if ( fromClass != null ) { return fromClass; @@ -1680,7 +1670,7 @@ private void bindSubclassCache() { } private void bindRootClassCache() { - final ModelsContext sourceModelContext = modelsContext(); + final var sourceModelContext = modelsContext(); final Cache cache = annotatedClass.getAnnotationUsage( Cache.class, sourceModelContext ); final Cacheable cacheable = annotatedClass.getAnnotationUsage( Cacheable.class, sourceModelContext ); @@ -1717,8 +1707,7 @@ private boolean isCacheable(Cacheable explicitCacheableAnn) { } private Cache buildCacheMock(ClassDetails classDetails) { - final CacheAnnotation cacheUsage = - HibernateAnnotations.CACHE.createUsage( modelsContext() ); + final var cacheUsage = HibernateAnnotations.CACHE.createUsage( modelsContext() ); cacheUsage.region( classDetails.getName() ); cacheUsage.usage( determineCacheConcurrencyStrategy() ); return cacheUsage; @@ -1798,9 +1787,8 @@ private void bindTableForDiscriminatedSubclass(String entityName) { ); } - final InFlightMetadataCollector collector = getMetadataCollector(); - final InFlightMetadataCollector.EntityTableXref superTableXref = - collector.getEntityTableXref( entityName ); + final var collector = getMetadataCollector(); + final var superTableXref = collector.getEntityTableXref( entityName ); final Table primaryTable = superTableXref.getPrimaryTable(); collector.addEntityTableXref( persistentClass.getEntityName(), @@ -1821,7 +1809,7 @@ private void bindTable( final String entityName = persistentClass.getEntityName(); - final EntityTableNamingStrategyHelper namingStrategyHelper = + final var namingStrategyHelper = new EntityTableNamingStrategyHelper( persistentClass.getClassName(), entityName, name ); final Identifier logicalName = isNotBlank( tableName ) @@ -1860,8 +1848,8 @@ private void bindTable( public void finalSecondaryTableBinding(PropertyHolder propertyHolder) { // This operation has to be done after the id definition of the persistence class. // ie after the properties parsing - final Iterator joinColumns = secondaryTableJoins.values().iterator(); - for ( Map.Entry entrySet : secondaryTables.entrySet() ) { + final var joinColumns = secondaryTableJoins.values().iterator(); + for ( var entrySet : secondaryTables.entrySet() ) { if ( !secondaryTablesFromAnnotation.containsKey( entrySet.getKey() ) ) { createPrimaryColumnsToSecondaryTable( joinColumns.next(), propertyHolder, entrySet.getValue() ); } @@ -1871,8 +1859,8 @@ public void finalSecondaryTableBinding(PropertyHolder propertyHolder) { public void finalSecondaryTableFromAnnotationBinding(PropertyHolder propertyHolder) { // This operation has to be done before the end of the FK second pass processing in order // to find the join columns belonging to secondary tables - Iterator joinColumns = secondaryTableFromAnnotationJoins.values().iterator(); - for ( Map.Entry entrySet : secondaryTables.entrySet() ) { + final var joinColumns = secondaryTableFromAnnotationJoins.values().iterator(); + for ( var entrySet : secondaryTables.entrySet() ) { if ( secondaryTablesFromAnnotation.containsKey( entrySet.getKey() ) ) { createPrimaryColumnsToSecondaryTable( joinColumns.next(), propertyHolder, entrySet.getValue() ); } @@ -1922,7 +1910,7 @@ else if ( first instanceof JoinColumn ) { } private AnnotatedJoinColumns createDefaultJoinColumn(PropertyHolder propertyHolder) { - final AnnotatedJoinColumns joinColumns = new AnnotatedJoinColumns(); + final var joinColumns = new AnnotatedJoinColumns(); joinColumns.setBuildingContext( context ); joinColumns.setJoins( secondaryTables ); joinColumns.setPropertyHolder( propertyHolder ); @@ -1945,7 +1933,7 @@ private AnnotatedJoinColumns createJoinColumns( return createDefaultJoinColumn( propertyHolder ); } else { - final AnnotatedJoinColumns columns = new AnnotatedJoinColumns(); + final var columns = new AnnotatedJoinColumns(); columns.setBuildingContext( context ); columns.setJoins( secondaryTables ); columns.setPropertyHolder( propertyHolder ); @@ -1969,7 +1957,7 @@ private AnnotatedJoinColumns createJoinColumns( } private void bindJoinToPersistentClass(Join join, AnnotatedJoinColumns joinColumns, MetadataBuildingContext context) { - DependantValue key = new DependantValue( context, join.getTable(), persistentClass.getIdentifier() ); + final var key = new DependantValue( context, join.getTable(), persistentClass.getIdentifier() ); join.setKey( key ); setForeignKeyNameIfDefined( join ); key.setOnDeleteAction( null ); @@ -1981,7 +1969,7 @@ private void bindJoinToPersistentClass(Join join, AnnotatedJoinColumns joinColum } private void setForeignKeyNameIfDefined(Join join) { - final SimpleValue key = (SimpleValue) join.getKey(); + final var key = (SimpleValue) join.getKey(); final SecondaryTable jpaSecondaryTable = findMatchingSecondaryTable( join ); if ( jpaSecondaryTable != null ) { final boolean noConstraintByDefault = context.getBuildingOptions().isNoConstraintByDefault(); @@ -2036,8 +2024,9 @@ private SecondaryRow findMatchingSecondaryRowAnnotation(String tableName) { private boolean equalsTableName(String physicalTableName, SecondaryRow secondaryRow) { final Identifier logicalName = context.getMetadataCollector().getDatabase().toIdentifier( secondaryRow.table() ); - final Identifier secondaryRowPhysicalTableName = context.getBuildingOptions().getPhysicalNamingStrategy() - .toPhysicalTableName( logicalName, EntityTableNamingStrategyHelper.jdbcEnvironment( context ) ); + final Identifier secondaryRowPhysicalTableName = + context.getBuildingOptions().getPhysicalNamingStrategy() + .toPhysicalTableName( logicalName, EntityTableNamingStrategyHelper.jdbcEnvironment( context ) ); return physicalTableName.equals( secondaryRowPhysicalTableName.render() ); } @@ -2126,8 +2115,7 @@ Join createJoin( persistentClass.addJoin( join ); final String entityName = persistentClass.getEntityName(); - final InFlightMetadataCollector.EntityTableXref tableXref - = getMetadataCollector().getEntityTableXref( entityName ); + final var tableXref = getMetadataCollector().getEntityTableXref( entityName ); assert tableXref != null : "Could not locate EntityTableXref for entity [" + entityName + "]"; tableXref.addSecondaryTable( logicalName, join ); @@ -2182,7 +2170,7 @@ private void processSecondaryTableCustomSql(Join join) { sqlInsert.callable(), fromResultCheckStyle( sqlInsert.check() ) ); - final Class expectationClass = sqlInsert.verify(); + final var expectationClass = sqlInsert.verify(); if ( expectationClass != Expectation.class ) { join.setInsertExpectation( getDefaultSupplier( expectationClass ) ); } @@ -2195,7 +2183,7 @@ private void processSecondaryTableCustomSql(Join join) { sqlUpdate.callable(), fromResultCheckStyle( sqlUpdate.check() ) ); - final Class expectationClass = sqlUpdate.verify(); + final var expectationClass = sqlUpdate.verify(); if ( expectationClass != Expectation.class ) { join.setUpdateExpectation( getDefaultSupplier( expectationClass ) ); } @@ -2208,7 +2196,7 @@ private void processSecondaryTableCustomSql(Join join) { sqlDelete.callable(), fromResultCheckStyle( sqlDelete.check() ) ); - final Class expectationClass = sqlDelete.verify(); + final var expectationClass = sqlDelete.verify(); if ( expectationClass != Expectation.class ) { join.setDeleteExpectation( getDefaultSupplier( expectationClass ) ); } @@ -2220,7 +2208,7 @@ public java.util.Map getSecondaryTables() { } public static String getCacheConcurrencyStrategy(CacheConcurrencyStrategy strategy) { - final org.hibernate.cache.spi.access.AccessType accessType = strategy.toAccessType(); + final var accessType = strategy.toAccessType(); return accessType == null ? null : accessType.getExternalName(); } @@ -2279,7 +2267,7 @@ private void bindFiltersInHierarchy() { private void bindFilters(AnnotationTarget element) { final Filters filters = getOverridableAnnotation( element, Filters.class, context ); if ( filters != null ) { - Collections.addAll( this.filters, filters.value() ); + addAll( this.filters, filters.value() ); } final Filter filter = element.getDirectAnnotationUsage( Filter.class ); if ( filter != null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ListBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ListBinder.java index 2bb4a6abac39..d83df6db7f87 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ListBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ListBinder.java @@ -93,7 +93,7 @@ private void createBackref() { final IndexBackref backref = new IndexBackref(); backref.setName( '_' + propertyName + "IndexBackref" ); backref.setOptional( true ); - backref.setUpdateable( false ); + backref.setUpdatable( false ); backref.setSelectable( false ); backref.setCollectionRole( collection.getRole() ); backref.setEntityName( collection.getOwner().getEntityName() ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/MapBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/MapBinder.java index b165ae84df54..fb4ba5db6eb6 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/MapBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/MapBinder.java @@ -545,7 +545,7 @@ private Component createIndexComponent(Collection collection, PersistentClass as newProperty.setCascade( property.getCascade() ); newProperty.setValueGeneratorCreator( property.getValueGeneratorCreator() ); newProperty.setInsertable( false ); - newProperty.setUpdateable( false ); + newProperty.setUpdatable( false ); newProperty.setMetaAttributes( property.getMetaAttributes() ); newProperty.setName( property.getName() ); newProperty.setNaturalIdentifier( false ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java index 0823642dd01a..2ef0f9b6ac24 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java @@ -471,7 +471,7 @@ private void handleMutability(Property property) { updatable = false; } property.setInsertable( insertable ); - property.setUpdateable( updatable ); + property.setUpdatable( updatable ); } private void handleOptional(Property property) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/Helper.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/Helper.java index df9a3f7e817c..bcbf1e3bf234 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/Helper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/Helper.java @@ -33,6 +33,7 @@ import org.hibernate.internal.util.StringHelper; import static org.hibernate.internal.util.StringHelper.nullIfEmpty; +import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.EMBEDDED; /** * @author Steve Ebersole @@ -97,7 +98,7 @@ public static Caching createNaturalIdCaching(JaxbHbmNaturalIdCacheType cacheElem } public static String getPropertyAccessorName(String access, boolean isEmbedded, String defaultAccess) { - return getValue( access, isEmbedded ? "embedded" : defaultAccess ); + return getValue( access, isEmbedded ? EMBEDDED.getExternalName() : defaultAccess ); } public static T getValue(T value, T defaultValue){ diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java index dc8f9fc46ba8..d53c452a2b8c 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java @@ -112,6 +112,7 @@ import static org.hibernate.internal.util.StringHelper.unqualify; import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty; import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty; +import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.EMBEDDED; /** * Responsible for coordinating the binding of all information inside entity tags ({@code }, etc). @@ -723,10 +724,10 @@ private void bindNonAggregatedCompositeEntityIdentifier( rootEntityDescriptor.setDeclaredIdentifierMapper( mapper ); final Property property = new Property(); property.setName( NavigablePath.IDENTIFIER_MAPPER_PROPERTY ); - property.setUpdateable( false ); + property.setUpdatable( false ); property.setInsertable( false ); property.setValue( mapper ); - property.setPropertyAccessorName( "embedded" ); + property.setPropertyAccessorName( EMBEDDED.getExternalName() ); rootEntityDescriptor.addProperty( property ); } @@ -757,7 +758,7 @@ private void finishBindingCompositeIdentifier( cid.setDynamic( !rootEntityDescriptor.hasPojoRepresentation() ); /* * Property prop = new Property(); prop.setName("id"); - * prop.setPropertyAccessorName("embedded"); prop.setValue(id); + * prop.setPropertyAccessorName(EMBEDDED.getExternalName()); prop.setValue(id); * entity.setIdentifierProperty(prop); */ } @@ -1047,7 +1048,7 @@ private void handleNaturalIdBinding( attributeBinding.setNaturalIdentifier( true ); if ( naturalIdMutability == NaturalIdMutability.IMMUTABLE ) { - attributeBinding.setUpdateable( false ); + attributeBinding.setUpdatable( false ); } final var metadataCollector = mappingDocument.getMetadataCollector(); @@ -1530,7 +1531,7 @@ private Property createEmbeddedAttribute( attribute.setValue( componentBinding ); bindProperty( sourceDocument, embeddedSource, attribute ); if ( embeddedSource.isVirtualAttribute() ) { - attribute.setPropertyAccessorName( "embedded" ); + attribute.setPropertyAccessorName( EMBEDDED.getExternalName() ); } return attribute; } @@ -2202,7 +2203,7 @@ private void bindProperty( if ( propertySource.isSingular() ) { final SingularAttributeSource singularAttributeSource = (SingularAttributeSource) propertySource; property.setInsertable( singularAttributeSource.isInsertable() ); - property.setUpdateable( singularAttributeSource.isUpdatable() ); + property.setUpdatable( singularAttributeSource.isUpdatable() ); // NOTE: Property#is refers to whether a property is lazy via bytecode enhancement (not proxies) property.setLazy( singularAttributeSource.isBytecodeLazy() ); handleGenerationTiming( mappingDocument, propertySource, property, singularAttributeSource.getGenerationTiming() ); @@ -2265,13 +2266,13 @@ private static void handleGenerationTiming( } // properties generated on update can never be updatable... - if ( property.isUpdateable() && timing.includesUpdate() ) { + if ( property.isUpdatable() && timing.includesUpdate() ) { log.tracef( "Property [%s] specified ALWAYS generation, setting updateable to false: %s", propertySource.getName(), mappingDocument.getOrigin() ); - property.setUpdateable( false ); + property.setUpdatable( false ); } } } @@ -2996,7 +2997,7 @@ protected void createBackReferences() { final Backref backref = new Backref(); backref.setName( '_' + collectionBinding.getOwnerEntityName() + "." + pluralAttributeSource.getName() + "Backref" ); backref.setOptional( true ); - backref.setUpdateable( false ); + backref.setUpdatable( false ); backref.setSelectable( false ); backref.setCollectionRole( collectionBinding.getRole() ); backref.setEntityName( collectionBinding.getOwner().getEntityName() ); @@ -3410,7 +3411,7 @@ protected void createBackReferences() { final IndexBackref backref = new IndexBackref(); backref.setName( '_' + collectionBinding.getOwnerEntityName() + "." + getPluralAttributeSource().getName() + "IndexBackref" ); backref.setOptional( true ); - backref.setUpdateable( false ); + backref.setUpdatable( false ); backref.setSelectable( false ); backref.setCollectionRole( collectionBinding.getRole() ); backref.setEntityName( collectionBinding.getOwner().getEntityName() ); @@ -3489,7 +3490,7 @@ private void createIndexBackRef( final IndexBackref backref = new IndexBackref(); backref.setName( '_' + collectionBinding.getOwnerEntityName() + "." + pluralAttributeSource.getName() + "IndexBackref" ); backref.setOptional( true ); - backref.setUpdateable( false ); + backref.setUpdatable( false ); backref.setSelectable( false ); backref.setCollectionRole( collectionBinding.getRole() ); backref.setEntityName( collectionBinding.getOwner().getEntityName() ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/AccessType.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/AccessType.java index f0fb8fc2b22e..1f431142b459 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/AccessType.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/AccessType.java @@ -4,8 +4,6 @@ */ package org.hibernate.boot.spi; -import org.hibernate.AssertionFailure; - /** * Enumerates various access strategies for accessing entity values. * @@ -38,17 +36,11 @@ public enum AccessType { * @return The external name */ public String getType() { - switch (this) { - case DEFAULT: - case PROPERTY: - return "property"; - case FIELD: - return "field"; - case RECORD: - return "record"; - default: - throw new AssertionFailure("Unknown AccessType"); - } + return switch ( this ) { + case DEFAULT, PROPERTY -> "property"; + case FIELD -> "field"; + case RECORD -> "record"; + }; } /** @@ -79,16 +71,11 @@ public static AccessType getAccessStrategy(String externalName) { * @return The Hibernate {@link AccessType} */ public static AccessType getAccessStrategy(jakarta.persistence.AccessType type) { - if ( type == null ) { - return DEFAULT; - } - switch ( type ) { - case FIELD: - return FIELD; - case PROPERTY: - return PROPERTY; - default: - throw new AssertionFailure( "unrecognized AccessType" ); - } + return type == null + ? DEFAULT + : switch ( type ) { + case FIELD -> FIELD; + case PROPERTY -> PROPERTY; + }; } } diff --git a/hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/NaturalIdDataCachingConfigImpl.java b/hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/NaturalIdDataCachingConfigImpl.java index 000253678cb0..6e28d79a2553 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/NaturalIdDataCachingConfigImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/NaturalIdDataCachingConfigImpl.java @@ -33,7 +33,7 @@ public NaturalIdDataCachingConfigImpl( private boolean hasAnyMutableNaturalIdProps() { for ( Property property : rootEntityDescriptor.getDeclaredProperties() ) { - if ( property.isNaturalIdentifier() && property.isUpdateable() ) { + if ( property.isNaturalIdentifier() && property.isUpdatable() ) { return true; } } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/ManagedTypeHelper.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/ManagedTypeHelper.java index 8ad1f9416a8b..d1cb35581d0a 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/ManagedTypeHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/ManagedTypeHelper.java @@ -71,26 +71,23 @@ protected TypeMeta computeValue(Class type) { }; /** - * @param type * @return true if and only if the type is assignable to a {@see Managed} type. */ - public static boolean isManagedType(final Class type) { + public static boolean isManagedType(final Class type) { return typeMetaCache.get( type ).isManagedType; } /** - * @param type * @return true if and only if the type is assignable to a {@see SelfDirtinessTracker} type. */ - public static boolean isSelfDirtinessTrackerType(final Class type) { + public static boolean isSelfDirtinessTrackerType(final Class type) { return typeMetaCache.get( type ).isSelfDirtinessTrackerType; } /** - * @param type * @return true if and only if the type is assignable to a {@see PersistentAttributeInterceptable} type. */ - public static boolean isPersistentAttributeInterceptableType(final Class type) { + public static boolean isPersistentAttributeInterceptableType(final Class type) { return typeMetaCache.get( type ).isPersistentAttributeInterceptable; } @@ -115,7 +112,6 @@ public static boolean isHibernateProxy(final Object entity) { } /** - * @param entity * @return true if and only if the entity implements {@see PersistentAttributeInterceptable} */ public static boolean isPersistentAttributeInterceptable(final Object entity) { @@ -126,7 +122,6 @@ public static boolean isPersistentAttributeInterceptable(final Object entity) { } /** - * @param entity * @return true if and only if the entity implements {@see SelfDirtinessTracker} */ public static boolean isSelfDirtinessTracker(final Object entity) { @@ -137,7 +132,6 @@ public static boolean isSelfDirtinessTracker(final Object entity) { } /** - * @param entity * @return true if and only if the entity implements {@see CompositeOwner} */ public static boolean isCompositeOwner(final Object entity) { @@ -148,7 +142,6 @@ public static boolean isCompositeOwner(final Object entity) { } /** - * @param entity * @return true if and only if the entity implements {@see CompositeTracker} */ public static boolean isCompositeTracker(final @Nullable Object entity) { @@ -173,7 +166,6 @@ public interface PersistentAttributeInterceptableAction { * Helper to execute an action on an entity, but exclusively if it's implementing the {@see PersistentAttributeInterceptable} * interface. Otherwise no action is performed. * - * @param entity * @param action The action to be performed; it should take the entity as first parameter, and an additional parameter T as second parameter. * @param optionalParam a parameter which can be passed to the action * @param the type of the additional parameter. @@ -194,8 +186,6 @@ public static void processIfPersistentAttributeInterceptable( * If the entity is implementing SelfDirtinessTracker, apply some action to it. * It is first cast to SelfDirtinessTracker using an optimal strategy. * If the entity does not implement SelfDirtinessTracker, no operation is performed. - * @param entity - * @param action */ public static void processIfSelfDirtinessTracker(final Object entity, final SelfDirtinessTrackerConsumer action) { if ( entity instanceof PrimeAmongSecondarySupertypes t ) { @@ -232,8 +222,6 @@ public interface ManagedEntityConsumer { * a parameter of type T. * It is first cast to SelfDirtinessTracker using an optimal strategy. * If the entity does not implement SelfDirtinessTracker, no operation is performed. - * @param entity - * @param action * @param optionalParam a parameter which can be passed to the action * @param the type of the additional parameter. */ diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackDefinitionResolver.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackDefinitionResolver.java index 6b0dde1a61e5..c4c8c95f0dde 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackDefinitionResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackDefinitionResolver.java @@ -176,7 +176,7 @@ private static List resolveEmbeddableCallbacks( final List methodsDetailsList = currentClass.getMethods(); for ( MethodDetails methodDetails : methodsDetailsList ) { if ( methodDetails.hasDirectAnnotationUsage( callbackType.getCallbackAnnotation() ) ) { - final Method method = (Method) methodDetails.toJavaMember(); + final Method method = methodDetails.toJavaMember(); final String methodName = method.getName(); final String callbackName = callbackType.getCallbackAnnotation().getName(); final String currentClassName = currentClass.getName(); diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/Component.java b/hibernate-core/src/main/java/org/hibernate/mapping/Component.java index d5840ddf5312..b1eb06828db9 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Component.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Component.java @@ -304,7 +304,7 @@ public void checkColumnDuplication(Set distinctColumns, String owner) { // since only one subtype can exist at one time final Map> distinctColumnsByClass = new HashMap<>(); for ( Property prop : properties ) { - if ( prop.isUpdateable() || prop.isInsertable() ) { + if ( prop.isUpdatable() || prop.isInsertable() ) { final String declaringClass = propertyDeclaringClasses.get( prop ); final Set set = distinctColumnsByClass.computeIfAbsent( declaringClass, @@ -507,7 +507,7 @@ public boolean[] getColumnUpdateability() { boolean[] result = new boolean[getColumnSpan()]; int i = 0; for ( Property prop : getProperties() ) { - i += copyFlags( prop.getValue().getColumnUpdateability(), result, i, prop.isUpdateable() ); + i += copyFlags( prop.getValue().getColumnUpdateability(), result, i, prop.isUpdatable() ); } if ( isPolymorphic() ) { i += copyFlags( getDiscriminator().getColumnUpdateability(), result, i, true ); diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/MappingHelper.java b/hibernate-core/src/main/java/org/hibernate/mapping/MappingHelper.java index 7e1354b585fb..a2f8ca349ae1 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/MappingHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/MappingHelper.java @@ -105,7 +105,7 @@ public static void checkPropertyColumnDuplication( List properties, String owner) throws MappingException { for ( Property prop : properties ) { - if ( prop.isUpdateable() || prop.isInsertable() ) { + if ( prop.isUpdatable() || prop.isInsertable() ) { prop.getValue().checkColumnDuplication( distinctColumns, owner ); } } 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 25efe81823e7..7cb73fedd726 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/Property.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/Property.java @@ -18,7 +18,6 @@ import org.hibernate.boot.model.relational.Database; import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementHelper; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.engine.spi.CascadeStyles; import org.hibernate.jpa.event.internal.EmbeddableCallback; @@ -26,6 +25,7 @@ import org.hibernate.metamodel.RepresentationMode; import org.hibernate.metamodel.spi.RuntimeModelCreationContext; import org.hibernate.property.access.spi.Getter; +import org.hibernate.property.access.spi.PropertyAccess; import org.hibernate.property.access.spi.PropertyAccessStrategy; import org.hibernate.property.access.spi.PropertyAccessStrategyResolver; import org.hibernate.property.access.spi.Setter; @@ -42,7 +42,10 @@ import static java.util.Collections.emptyList; import static java.util.Collections.unmodifiableList; import static org.hibernate.boot.model.internal.BinderHelper.renderCascadeTypeList; +import static org.hibernate.cfg.MappingSettings.WRAPPER_ARRAY_HANDLING; import static org.hibernate.internal.util.StringHelper.isBlank; +import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.BASIC; +import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.MAP; /** * A mapping model object representing a property or field of an {@linkplain PersistentClass entity} @@ -54,7 +57,7 @@ public class Property implements Serializable, MetaAttributable { private String name; private Value value; private String cascade; - private boolean updateable = true; + private boolean updatable = true; private boolean insertable = true; private boolean selectable = true; private boolean optimisticLocked = true; @@ -124,9 +127,10 @@ public Value getValue() { } public void resetUpdateable(boolean updateable) { - setUpdateable( updateable ); - boolean[] columnUpdateability = getValue().getColumnUpdateability(); - for (int i=0; i getMetaAttributes() { @@ -299,17 +320,18 @@ public boolean isValid(MappingContext mappingContext) throws MappingException { final Value value = getValue(); if ( value instanceof BasicValue basicValue && basicValue.isDisallowedWrapperArray() ) { throw new MappingException( - "The property " + persistentClass.getEntityName() + "#" + name + - " uses a wrapper type Byte[]/Character[] which indicates an issue in your domain model. " + - "These types have been treated like byte[]/char[] until Hibernate 6.2 which meant that " + - "null elements were not allowed, but on JDBC were processed like VARBINARY or VARCHAR. " + - "If you don't use nulls in your arrays, change the type of the property to byte[]/char[]. " + - "To allow explicit uses of the wrapper types Byte[]/Character[] which allows null element " + - "but has a different serialization format than before Hibernate 6.2, configure the " + - "setting " + AvailableSettings.WRAPPER_ARRAY_HANDLING + " to the value " + WrapperArrayHandling.ALLOW + ". " + - "To revert to the legacy treatment of these types, configure the value to " + WrapperArrayHandling.LEGACY + ". " + - "For more information on this matter, consult the migration guide of Hibernate 6.2 " + - "and the Javadoc of the org.hibernate.cfg.AvailableSettings.WRAPPER_ARRAY_HANDLING field." + """ + The property %s.%s uses a wrapper type Byte[]/Character[] which indicates an issue in your domain model. \ + These types have been treated like byte[]/char[] until Hibernate 6.2 which meant that null elements were \ + not allowed, but on JDBC were processed like VARBINARY or VARCHAR. If you don't use nulls in your arrays, \ + change the type of the property to byte[]/char[]. To allow explicit uses of the types Byte[]/Character[], \ + allowing null elements, but with a different serialization format than before Hibernate 6.2, configure \ + the setting '%s' to the value '%s'. To revert to the legacy treatment of these types, configure the value to '%s'. \ + For more information on this matter, consult the migration guide of Hibernate 6.2 and the Javadoc of the \ + field 'org.hibernate.cfg.AvailableSettings.WRAPPER_ARRAY_HANDLING'.\ + """ + .formatted( persistentClass.getEntityName(), name, WRAPPER_ARRAY_HANDLING, + WrapperArrayHandling.ALLOW, WrapperArrayHandling.LEGACY ) ); } return value.isValid( mappingContext ); @@ -330,7 +352,7 @@ public void setLazy(boolean lazy) { * instance in its "base fetch group". It affects whether we list * this property's columns in the SQL select for the owning entity * when we load its "base fetch group". The actual value that is set - * varies based on the nature (basic, etc) of the property. + * varies based on the nature (basic, or whatever) of the property. * * @apiNote This method reports whether the property is considered * part of the base fetch group based solely on the information in @@ -338,15 +360,10 @@ public void setLazy(boolean lazy) { * is also accounts for other details. */ public boolean isLazy() { - if ( value instanceof ToOne ) { - // For a many-to-one, this is always false. Whether the - // association is EAGER, PROXY or NO-PROXY we always want - // to select the foreign key - return false; - } - else { - return lazy; - } + // For a many-to-one, this is always false. Whether the + // association is EAGER, PROXY or NO-PROXY we always want + // to select the foreign key + return !(value instanceof ToOne) && lazy; } public String getLazyGroup() { @@ -389,52 +406,72 @@ public void setSelectable(boolean selectable) { this.selectable = selectable; } + private PropertyAccess buildPropertyAccess(Class clazz) { + return getPropertyAccessStrategy( clazz ).buildPropertyAccess( clazz, name, true ); + } + // todo : remove @Internal - public Getter getGetter(Class clazz) throws MappingException { - return getPropertyAccessStrategy( clazz ).buildPropertyAccess( clazz, name, true ).getGetter(); + public Getter getGetter(Class clazz) throws MappingException { + return buildPropertyAccess( clazz ).getGetter(); } // todo : remove @Internal - public Setter getSetter(Class clazz) throws MappingException { - return getPropertyAccessStrategy( clazz ).buildPropertyAccess( clazz, name, true ).getSetter(); + public Setter getSetter(Class clazz) throws MappingException { + return buildPropertyAccess( clazz ).getSetter(); } // todo : remove @Internal - public PropertyAccessStrategy getPropertyAccessStrategy(Class clazz) throws MappingException { - final PropertyAccessStrategy propertyAccessStrategy = getPropertyAccessStrategy(); + public PropertyAccessStrategy getPropertyAccessStrategy(Class clazz) throws MappingException { + final var propertyAccessStrategy = getPropertyAccessStrategy(); if ( propertyAccessStrategy != null ) { return propertyAccessStrategy; } - String accessName = getPropertyAccessorName(); - if ( accessName == null ) { - if ( clazz == null || java.util.Map.class.equals( clazz ) ) { - accessName = "map"; - } - else { - accessName = "property"; - } + else { + return getPropertyAccessStrategyResolver() + .resolvePropertyAccessStrategy( + clazz, + propertyAccessorName( clazz ), + isMapEntity( clazz ) + ? RepresentationMode.MAP + : RepresentationMode.POJO + ); } + } - final RepresentationMode representationMode = clazz == null || java.util.Map.class.equals( clazz ) - ? RepresentationMode.MAP - : RepresentationMode.POJO; - + private PropertyAccessStrategyResolver getPropertyAccessStrategyResolver() { return resolveServiceRegistry() - .requireService( PropertyAccessStrategyResolver.class ) - .resolvePropertyAccessStrategy( clazz, accessName, representationMode ); + .requireService( PropertyAccessStrategyResolver.class ); + } + + private String propertyAccessorName(Class clazz) { + final String accessorName = getPropertyAccessorName(); + if ( accessorName == null ) { + return isMapEntity( clazz ) + ? MAP.getExternalName() + : BASIC.getExternalName(); + } + else { + return accessorName; + } } - ServiceRegistry resolveServiceRegistry() { + private static boolean isMapEntity(Class clazz) { + return clazz == null || Map.class.equals( clazz ); + } + + private ServiceRegistry resolveServiceRegistry() { if ( getPersistentClass() != null ) { return getPersistentClass().getServiceRegistry(); } - if ( getValue() != null ) { + else if ( getValue() != null ) { return getValue().getServiceRegistry(); } - throw new HibernateException( "Could not resolve ServiceRegistry" ); + else { + throw new HibernateException( "Could not resolve ServiceRegistry" ); + } } public boolean isNaturalIdentifier() { @@ -503,7 +540,7 @@ public Property copy() { property.setName( getName() ); property.setValue( getValue() ); property.setCascade( getCascade() ); - property.setUpdateable( isUpdateable() ); + property.setUpdatable( isUpdatable() ); property.setInsertable( isInsertable() ); property.setSelectable( isSelectable() ); property.setOptimisticLocked( isOptimisticLocked() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyPojoStandard.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyPojoStandard.java index 7d2fe8d91920..0284d4137c5e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyPojoStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityRepresentationStrategyPojoStandard.java @@ -33,7 +33,6 @@ import org.hibernate.tuple.entity.EntityMetamodel; import org.hibernate.type.CompositeType; import org.hibernate.type.descriptor.java.JavaType; -import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry; import org.hibernate.type.spi.CompositeTypeImplementor; import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptableType; @@ -67,15 +66,15 @@ public EntityRepresentationStrategyPojoStandard( PersistentClass bootDescriptor, EntityPersister runtimeDescriptor, RuntimeModelCreationContext creationContext) { - final JavaTypeRegistry jtdRegistry = creationContext.getTypeConfiguration().getJavaTypeRegistry(); + final var registry = creationContext.getTypeConfiguration().getJavaTypeRegistry(); final Class mappedJavaType = bootDescriptor.getMappedClass(); - this.mappedJtd = jtdRegistry.resolveEntityTypeDescriptor( mappedJavaType ); + mappedJtd = registry.resolveEntityTypeDescriptor( mappedJavaType ); final Class proxyJavaType = bootDescriptor.getProxyInterface(); - this.proxyJtd = proxyJavaType != null ? jtdRegistry.getDescriptor( proxyJavaType ) : null; + proxyJtd = proxyJavaType != null ? registry.getDescriptor( proxyJavaType ) : null; - this.isBytecodeEnhanced = isPersistentAttributeInterceptableType( mappedJavaType ); + isBytecodeEnhanced = isPersistentAttributeInterceptableType( mappedJavaType ); final Property identifierProperty = bootDescriptor.getIdentifierProperty(); if ( identifierProperty == null ) { @@ -106,13 +105,13 @@ public EntityRepresentationStrategyPojoStandard( identifierPropertyAccess = makePropertyAccess( identifierProperty ); } - this.strategySelector = creationContext.getServiceRegistry().getService( StrategySelector.class ); + strategySelector = creationContext.getServiceRegistry().getService( StrategySelector.class ); - final BytecodeProvider bytecodeProvider = + final var bytecodeProvider = creationContext.getBootstrapContext().getServiceRegistry() .requireService( BytecodeProvider.class ); - this.proxyFactory = resolveProxyFactory( + proxyFactory = resolveProxyFactory( bootDescriptor, runtimeDescriptor, proxyJtd, @@ -120,10 +119,10 @@ public EntityRepresentationStrategyPojoStandard( creationContext ); - this.propertyAccessMap = buildPropertyAccessMap( bootDescriptor ); - this.reflectionOptimizer = resolveReflectionOptimizer( bytecodeProvider ); + propertyAccessMap = buildPropertyAccessMap( bootDescriptor ); + reflectionOptimizer = resolveReflectionOptimizer( bytecodeProvider ); - this.instantiator = determineInstantiator( bootDescriptor, runtimeDescriptor.getEntityMetamodel() ); + instantiator = determineInstantiator( bootDescriptor, runtimeDescriptor.getEntityMetamodel() ); } private ProxyFactory resolveProxyFactory( @@ -142,10 +141,9 @@ private ProxyFactory resolveProxyFactory( return null; } else { - final EntityMetamodel entityMetamodel = entityPersister.getEntityMetamodel(); + final var entityMetamodel = entityPersister.getEntityMetamodel(); if ( proxyJavaType != null && entityMetamodel.isLazy() ) { - final ProxyFactory proxyFactory = - createProxyFactory( bootDescriptor, bytecodeProvider, creationContext ); + final var proxyFactory = createProxyFactory( bootDescriptor, bytecodeProvider, creationContext ); if ( proxyFactory == null ) { entityMetamodel.setLazy( false ); } @@ -184,42 +182,10 @@ private ProxyFactory createProxyFactory( BytecodeProvider bytecodeProvider, RuntimeModelCreationContext creationContext) { - // HHH-17578 - We need to preserve the order of the interfaces to ensure - // that the most general @Proxy declared interface at the top of a class - // hierarchy will be used first when a HibernateProxy decides what it - // should implement. - final Set> proxyInterfaces = new LinkedHashSet<>(); - final Class mappedClass = mappedJtd.getJavaTypeClass(); - final Class proxyInterface = proxyJtd != null ? proxyJtd.getJavaTypeClass() : null; - - if ( proxyInterface != null && ! mappedClass.equals( proxyInterface ) ) { - if ( ! proxyInterface.isInterface() ) { - throw new MappingException( - "proxy must be either an interface, or the class itself: " + bootDescriptor.getEntityName() - ); - } - proxyInterfaces.add( proxyInterface ); - } + final Class proxyInterface = proxyJtd == null ? null : proxyJtd.getJavaTypeClass(); - if ( mappedClass.isInterface() ) { - proxyInterfaces.add( mappedClass ); - } - - for ( Subclass subclass : bootDescriptor.getSubclasses() ) { - final Class subclassProxy = subclass.getProxyInterface(); - final Class subclassClass = subclass.getMappedClass(); - if ( subclassProxy != null && !subclassClass.equals( subclassProxy ) ) { - if ( !subclassProxy.isInterface() ) { - throw new MappingException( - "proxy must be either an interface, or the class itself: " + subclass.getEntityName() - ); - } - proxyInterfaces.add( subclassProxy ); - } - } - - proxyInterfaces.add( HibernateProxy.class ); + final Set> proxyInterfaces = proxyInterfaces( bootDescriptor, proxyInterface, mappedClass ); final Class clazz = bootDescriptor.getMappedClass(); final Method idGetterMethod; @@ -254,12 +220,72 @@ private ProxyFactory createProxyFactory( idSetterMethod == null || proxyInterface == null ? null : getMethod( proxyInterface, idSetterMethod ); - final ProxyFactory proxyFactory = + return instantiateProxyFactory( + bootDescriptor, + bytecodeProvider, + creationContext, + proxyGetIdentifierMethod, + proxySetIdentifierMethod, + mappedClass, + proxyInterfaces + ); + } + + private static Set> proxyInterfaces( + PersistentClass bootDescriptor, + Class proxyInterface, + Class mappedClass) { + // HHH-17578 - We need to preserve the order of the interfaces to ensure + // that the most general @Proxy declared interface at the top of a class + // hierarchy will be used first when a HibernateProxy decides what it + // should implement. + + final Set> proxyInterfaces = new LinkedHashSet<>(); + + if ( proxyInterface != null && ! mappedClass.equals( proxyInterface ) ) { + if ( ! proxyInterface.isInterface() ) { + throw new MappingException( "proxy must be either an interface, or the class itself: " + + bootDescriptor.getEntityName() ); + } + proxyInterfaces.add( proxyInterface ); + } + + if ( mappedClass.isInterface() ) { + proxyInterfaces.add( mappedClass ); + } + + for ( Subclass subclass : bootDescriptor.getSubclasses() ) { + final Class subclassProxy = subclass.getProxyInterface(); + final Class subclassClass = subclass.getMappedClass(); + if ( subclassProxy != null && !subclassClass.equals( subclassProxy ) ) { + if ( !subclassProxy.isInterface() ) { + throw new MappingException( "proxy must be either an interface, or the class itself: " + + subclass.getEntityName() ); + } + proxyInterfaces.add( subclassProxy ); + } + } + + proxyInterfaces.add( HibernateProxy.class ); + + return proxyInterfaces; + } + + private static ProxyFactory instantiateProxyFactory( + PersistentClass bootDescriptor, + BytecodeProvider bytecodeProvider, + RuntimeModelCreationContext creationContext, + Method proxyGetIdentifierMethod, + Method proxySetIdentifierMethod, + Class mappedClass, + Set> proxyInterfaces) { + final var proxyFactory = bytecodeProvider.getProxyFactoryFactory() .buildProxyFactory( creationContext.getSessionFactory() ); + final String entityName = bootDescriptor.getEntityName(); try { proxyFactory.postInstantiate( - bootDescriptor.getEntityName(), + entityName, mappedClass, proxyInterfaces, proxyGetIdentifierMethod, @@ -268,24 +294,21 @@ private ProxyFactory createProxyFactory( ? (CompositeType) bootDescriptor.getIdentifier().getType() : null ); - - return proxyFactory; } catch (HibernateException he) { - LOG.unableToCreateProxyFactory( bootDescriptor.getEntityName(), he ); + LOG.unableToCreateProxyFactory( entityName, he ); return null; } + return proxyFactory; } private ReflectionOptimizer resolveReflectionOptimizer(BytecodeProvider bytecodeProvider) { - return bytecodeProvider.getReflectionOptimizer( - mappedJtd.getJavaTypeClass(), - propertyAccessMap - ); + return bytecodeProvider.getReflectionOptimizer( mappedJtd.getJavaTypeClass(), propertyAccessMap ); } private PropertyAccess makePropertyAccess(Property bootAttributeDescriptor) { final Class mappedClass = mappedJtd.getJavaTypeClass(); + final String descriptorName = bootAttributeDescriptor.getName(); final var strategy = propertyAccessStrategy( bootAttributeDescriptor, mappedClass, strategySelector ); if ( strategy == null ) { throw new HibernateException( @@ -293,11 +316,11 @@ private PropertyAccess makePropertyAccess(Property bootAttributeDescriptor) { Locale.ROOT, "Could not resolve PropertyAccess for attribute `%s#%s`", mappedJtd.getTypeName(), - bootAttributeDescriptor.getName() + descriptorName ) ); } - return strategy.buildPropertyAccess( mappedClass, bootAttributeDescriptor.getName(), true ); + return strategy.buildPropertyAccess( mappedClass, descriptorName, true ); } @Override @@ -341,7 +364,7 @@ public PropertyAccess resolvePropertyAccess(Property bootAttributeDescriptor) { return identifierPropertyAccess; } else { - final PropertyAccess propertyAccess = propertyAccessMap.get( bootAttributeDescriptor.getName() ); + final var propertyAccess = propertyAccessMap.get( bootAttributeDescriptor.getName() ); if ( propertyAccess != null ) { return propertyAccess; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java index e9eb135a48ec..1424e73be38b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java @@ -219,7 +219,7 @@ private EmbeddableMappingTypeImpl( } else { insertable = componentProperty.isInsertable(); - updatable = componentProperty.isUpdateable(); + updatable = componentProperty.isUpdatable(); } this.aggregateMapping = SelectableMappingImpl.from( bootDescriptor.getOwner().getTable().getQualifiedName( creationContext.getSqlStringGenerationContext() ), diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java index 26fdec0d2dae..a2a02d89c674 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java @@ -399,7 +399,7 @@ protected static AttributeMetadata getAttributeMetadata( getMutabilityPlan( bootProperty, attrType, creationProcess ), bootProperty.getValue().isNullable(), bootProperty.isInsertable(), - bootProperty.isUpdateable(), + bootProperty.isUpdatable(), bootProperty.isOptimisticLocked(), bootProperty.isSelectable(), cascadeStyle @@ -410,7 +410,7 @@ private static MutabilityPlan getMutabilityPlan( Property bootProperty, Type attrType, MappingModelCreationProcess creationProcess) { - if ( bootProperty.isUpdateable() ) { + if ( bootProperty.isUpdatable() ) { return new MutabilityPlan<>() { final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory(); @@ -653,7 +653,7 @@ public static PluralAttributeMapping buildPluralAttributeMapping( ImmutableMutabilityPlan.instance(), bootProperty.isOptional(), bootProperty.isInsertable(), - bootProperty.isUpdateable(), + bootProperty.isUpdatable(), bootProperty.isOptimisticLocked(), bootProperty.isSelectable(), cascadeStyle diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleAttributeMetadata.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleAttributeMetadata.java index 781f4863cc5e..4e110501f1b5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleAttributeMetadata.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleAttributeMetadata.java @@ -34,7 +34,7 @@ public SimpleAttributeMetadata( mutabilityPlan, value.isNullable(), bootProperty.isInsertable(), - bootProperty.isUpdateable(), + bootProperty.isUpdatable(), bootProperty.isOptimisticLocked(), bootProperty.isSelectable() ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 3f0b1e59de4c..49fada4dcf88 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -5479,7 +5479,7 @@ else if ( attrType instanceof AnyType anyType ) { mutabilityPlan, bootProperty.isOptional(), bootProperty.isInsertable(), - bootProperty.isUpdateable(), + bootProperty.isUpdatable(), bootProperty.isOptimisticLocked(), bootProperty.isSelectable() ); diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/AccessStrategyHelper.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/AccessStrategyHelper.java index 8fdfb31544a9..dbb151d3d2b3 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/AccessStrategyHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/AccessStrategyHelper.java @@ -13,7 +13,6 @@ import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor; import org.hibernate.engine.spi.CompositeOwner; import org.hibernate.engine.spi.CompositeTracker; -import org.hibernate.engine.spi.PersistentAttributeInterceptor; import org.hibernate.internal.util.NullnessUtil; import jakarta.persistence.Access; @@ -116,8 +115,8 @@ public static void handleEnhancedInjection(Object target, @Nullable Object value // This marks the attribute as initialized, so it doesn't get lazily loaded afterward if ( ( enhancementState & PERSISTENT_ATTRIBUTE_INTERCEPTABLE_MASK ) != 0 ) { - PersistentAttributeInterceptor interceptor = asPersistentAttributeInterceptable( target ).$$_hibernate_getInterceptor(); - if ( interceptor instanceof BytecodeLazyAttributeInterceptor lazyAttributeInterceptor ) { + if ( asPersistentAttributeInterceptable( target ).$$_hibernate_getInterceptor() + instanceof BytecodeLazyAttributeInterceptor lazyAttributeInterceptor ) { lazyAttributeInterceptor.attributeInitialized( propertyName ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/ChainedPropertyAccessImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/ChainedPropertyAccessImpl.java index 16831fff6b99..3554009aad47 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/ChainedPropertyAccessImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/ChainedPropertyAccessImpl.java @@ -13,6 +13,7 @@ import org.hibernate.internal.util.NullnessUtil; import org.hibernate.property.access.spi.Getter; import org.hibernate.property.access.spi.PropertyAccess; +import org.hibernate.property.access.spi.PropertyAccessException; import org.hibernate.property.access.spi.PropertyAccessStrategy; import org.hibernate.property.access.spi.Setter; @@ -53,12 +54,14 @@ public Setter getSetter() { return result; } - @SuppressWarnings("rawtypes") @Override - public @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { + public @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { @Nullable Object result = owner; for ( int i = 0; i < propertyAccesses.length; i++ ) { - result = propertyAccesses[i].getGetter().getForInsert( NullnessUtil.castNonNull( result ), mergeMap, session ); + if ( result == null ) { + throw new PropertyAccessException( "Could not chain accessor because result of previous accessor was null" ); + } + result = propertyAccesses[i].getGetter().getForInsert( result, mergeMap, session ); } return result; } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessBasicImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessBasicImpl.java index aaa0f61683b9..764bc3afa2dc 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessBasicImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessBasicImpl.java @@ -14,7 +14,6 @@ import org.hibernate.property.access.spi.Setter; import org.hibernate.property.access.spi.SetterMethodImpl; -import org.jboss.logging.Logger; import org.checkerframework.checker.nullness.qual.Nullable; @@ -26,7 +25,6 @@ * @see PropertyAccessStrategyBasicImpl */ public class PropertyAccessBasicImpl implements PropertyAccess { - private static final Logger log = Logger.getLogger( PropertyAccessBasicImpl.class ); private final PropertyAccessStrategyBasicImpl strategy; private final GetterMethodImpl getter; @@ -40,16 +38,12 @@ public PropertyAccessBasicImpl( this.strategy = strategy; final Method getterMethod = ReflectHelper.findGetterMethod( containerJavaType, propertyName ); - this.getter = new GetterMethodImpl( containerJavaType, propertyName, getterMethod ); + getter = new GetterMethodImpl( containerJavaType, propertyName, getterMethod ); - final Method setterMethod; - if ( setterRequired ) { - setterMethod = ReflectHelper.findSetterMethod( containerJavaType, propertyName, getterMethod.getReturnType() ); - } - else { - setterMethod = ReflectHelper.setterMethodOrNull( containerJavaType, propertyName, getterMethod.getReturnType() ); - } - this.setter = setterMethod != null + final Method setterMethod = setterRequired + ? ReflectHelper.findSetterMethod( containerJavaType, propertyName, getterMethod.getReturnType() ) + : ReflectHelper.setterMethodOrNull( containerJavaType, propertyName, getterMethod.getReturnType() ); + setter = setterMethod != null ? new SetterMethodImpl( containerJavaType, propertyName, setterMethod ) : null; } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessCompositeUserTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessCompositeUserTypeImpl.java index 3f8efecf4bfc..bdebd0ac4dab 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessCompositeUserTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessCompositeUserTypeImpl.java @@ -55,9 +55,8 @@ public Getter getGetter() { return strategy.compositeUserType.getPropertyValue( owner, propertyIndex ); } - @SuppressWarnings("rawtypes") @Override - public @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { + public @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { return get( owner ); } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEmbeddedImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEmbeddedImpl.java index 96e43f48eb22..b63b3eb5ceff 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEmbeddedImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEmbeddedImpl.java @@ -67,9 +67,8 @@ public Object get(Object owner) { return owner; } - @SuppressWarnings("rawtypes") @Override - public Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { + public Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { return owner; } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEnhancedImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEnhancedImpl.java index e999716d32ad..d64713d79685 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEnhancedImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEnhancedImpl.java @@ -45,9 +45,10 @@ public PropertyAccessEnhancedImpl( @Nullable AccessType classAccessType) { this.strategy = strategy; - final AccessType propertyAccessType = classAccessType == null ? - AccessStrategyHelper.getAccessType( containerJavaType, propertyName ) : - classAccessType; + final AccessType propertyAccessType = + classAccessType == null + ? AccessStrategyHelper.getAccessType( containerJavaType, propertyName ) + : classAccessType; switch ( propertyAccessType ) { case FIELD: { @@ -57,8 +58,8 @@ public PropertyAccessEnhancedImpl( "Could not locate field for property named [" + containerJavaType.getName() + "#" + propertyName + "]" ); } - this.getter = new GetterFieldImpl( containerJavaType, propertyName, field ); - this.setter = new EnhancedSetterImpl( containerJavaType, propertyName, field ); + getter = new GetterFieldImpl( containerJavaType, propertyName, field ); + setter = new EnhancedSetterImpl( containerJavaType, propertyName, field ); break; } case PROPERTY: { @@ -68,8 +69,8 @@ public PropertyAccessEnhancedImpl( "Could not locate getter for property named [" + containerJavaType.getName() + "#" + propertyName + "]" ); } - this.getter = propertyGetter( classAccessType, containerJavaType, propertyName, getterMethod ); - this.setter = propertySetter( classAccessType, containerJavaType, propertyName, getterMethod.getReturnType() ); + getter = propertyGetter( classAccessType, containerJavaType, propertyName, getterMethod ); + setter = propertySetter( classAccessType, containerJavaType, propertyName, getterMethod.getReturnType() ); break; } default: { diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessFieldImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessFieldImpl.java index dc5f674b61fb..bed336646207 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessFieldImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessFieldImpl.java @@ -30,8 +30,8 @@ public PropertyAccessFieldImpl( this.strategy = strategy; final Field field = ReflectHelper.findField( containerJavaType, propertyName ); - this.getter = new GetterFieldImpl( containerJavaType, propertyName, field ); - this.setter = new SetterFieldImpl( containerJavaType, propertyName, field ); + getter = new GetterFieldImpl( containerJavaType, propertyName, field ); + setter = new SetterFieldImpl( containerJavaType, propertyName, field ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessGetterImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessGetterImpl.java index 9abc5fbd4be9..2cc110a1fbab 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessGetterImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessGetterImpl.java @@ -35,23 +35,23 @@ public PropertyAccessGetterImpl(PropertyAccessStrategy strategy, Class contai final AccessType propertyAccessType = AccessStrategyHelper.getAccessType( containerJavaType, propertyName ); switch ( propertyAccessType ) { case FIELD: { - Field field = AccessStrategyHelper.fieldOrNull( containerJavaType, propertyName ); + final Field field = AccessStrategyHelper.fieldOrNull( containerJavaType, propertyName ); if ( field == null ) { throw new PropertyAccessBuildingException( "Could not locate field for property named [" + containerJavaType.getName() + "#" + propertyName + "]" ); } - this.getter = fieldGetter( containerJavaType, propertyName, field ); + getter = fieldGetter( containerJavaType, propertyName, field ); break; } case PROPERTY: { - Method getterMethod = getterMethodOrNull( containerJavaType, propertyName ); + final Method getterMethod = getterMethodOrNull( containerJavaType, propertyName ); if ( getterMethod == null ) { throw new PropertyAccessBuildingException( "Could not locate getter for property named [" + containerJavaType.getName() + "#" + propertyName + "]" ); } - this.getter = propertyGetter( containerJavaType, propertyName, getterMethod ); + getter = propertyGetter( containerJavaType, propertyName, getterMethod ); break; } default: { diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMapImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMapImpl.java index 1cae23e3de1e..aa664cefe88c 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMapImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMapImpl.java @@ -64,7 +64,7 @@ public GetterImpl(String propertyName) { } @Override - public @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { + public @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { return get( owner ); } @@ -103,7 +103,7 @@ public SetterImpl(String propertyName) { } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings({"unchecked", "rawtypes"}) public void set(Object target, @Nullable Object value) { ( (Map) target ).put( propertyName, value ); } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMixedImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMixedImpl.java index 5af4b64b5df1..f158ef6b015f 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMixedImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMixedImpl.java @@ -40,27 +40,27 @@ public PropertyAccessMixedImpl(PropertyAccessStrategy strategy, Class contain final AccessType propertyAccessType = AccessStrategyHelper.getAccessType( containerJavaType, propertyName ); switch ( propertyAccessType ) { case FIELD: { - Field field = AccessStrategyHelper.fieldOrNull( containerJavaType, propertyName ); + final Field field = AccessStrategyHelper.fieldOrNull( containerJavaType, propertyName ); if ( field == null ) { throw new PropertyAccessBuildingException( "Could not locate field for property named [" + containerJavaType.getName() + "#" + propertyName + "]" ); } - this.getter = fieldGetter( containerJavaType, propertyName, field ); - this.setter = fieldSetter( containerJavaType, propertyName, field ); + getter = fieldGetter( containerJavaType, propertyName, field ); + setter = fieldSetter( containerJavaType, propertyName, field ); break; } case PROPERTY: { - Method getterMethod = getterMethodOrNull( containerJavaType, propertyName ); + final Method getterMethod = getterMethodOrNull( containerJavaType, propertyName ); if ( getterMethod == null ) { throw new PropertyAccessBuildingException( "Could not locate getter for property named [" + containerJavaType.getName() + "#" + propertyName + "]" ); } - Method setterMethod = findSetterMethod( containerJavaType, propertyName, getterMethod.getReturnType() ); + final Method setterMethod = findSetterMethod( containerJavaType, propertyName, getterMethod.getReturnType() ); - this.getter = propertyGetter( containerJavaType, propertyName, getterMethod ); - this.setter = propertySetter( containerJavaType, propertyName, setterMethod ); + getter = propertyGetter( containerJavaType, propertyName, getterMethod ); + setter = propertySetter( containerJavaType, propertyName, setterMethod ); break; } default: { diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBackRefImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBackRefImpl.java index 9b231b7c2afa..29c093dfdbb6 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBackRefImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBackRefImpl.java @@ -4,6 +4,7 @@ */ package org.hibernate.property.access.internal; +import java.io.Serial; import java.io.Serializable; import java.lang.reflect.Member; import java.lang.reflect.Method; @@ -33,6 +34,7 @@ public String toString() { return ""; } + @Serial public Object readResolve() { return UNKNOWN; } @@ -92,8 +94,7 @@ public Object get(Object owner) { } @Override - @SuppressWarnings("rawtypes") - public Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { + public Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { return session.getPersistenceContextInternal().getOwnerId( entityName, propertyName, owner, mergeMap ); } @@ -127,7 +128,7 @@ private static class SetterImpl implements Setter { /** * Singleton access */ - public static final SetterImpl INSTANCE = new SetterImpl(); + public static final Setter INSTANCE = new SetterImpl(); @Override public void set(Object target, @Nullable Object value) { diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBasicImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBasicImpl.java index 637b961d97ec..92d6dbb8c949 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBasicImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBasicImpl.java @@ -18,7 +18,7 @@ public class PropertyAccessStrategyBasicImpl implements PropertyAccessStrategy { /** * Singleton access */ - public static final PropertyAccessStrategyBasicImpl INSTANCE = new PropertyAccessStrategyBasicImpl(); + public static final PropertyAccessStrategy INSTANCE = new PropertyAccessStrategyBasicImpl(); @Override public PropertyAccess buildPropertyAccess(Class containerJavaType, final String propertyName, boolean setterRequired) { diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyChainedImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyChainedImpl.java index 2fedd44745c6..26591827acd1 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyChainedImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyChainedImpl.java @@ -21,7 +21,7 @@ public PropertyAccessStrategyChainedImpl(PropertyAccessStrategy... chain) { @Override public PropertyAccess buildPropertyAccess(Class containerJavaType, String propertyName, boolean setterRequired) { - for ( PropertyAccessStrategy candidate : chain ) { + for ( var candidate : chain ) { try { return candidate.buildPropertyAccess( containerJavaType, propertyName, true ); } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyEmbeddedImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyEmbeddedImpl.java index 08e6459d880e..18639f98a36b 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyEmbeddedImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyEmbeddedImpl.java @@ -17,7 +17,7 @@ public class PropertyAccessStrategyEmbeddedImpl implements PropertyAccessStrateg /** * Singleton access */ - public static final PropertyAccessStrategyEmbeddedImpl INSTANCE = new PropertyAccessStrategyEmbeddedImpl(); + public static final PropertyAccessStrategy INSTANCE = new PropertyAccessStrategyEmbeddedImpl(); @Override public PropertyAccess buildPropertyAccess(Class containerJavaType, String propertyName, boolean setterRequired) { diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyEnhancedImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyEnhancedImpl.java index 6707a9c99504..ac16651a2deb 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyEnhancedImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyEnhancedImpl.java @@ -18,22 +18,20 @@ * @author Gavin King */ public class PropertyAccessStrategyEnhancedImpl implements PropertyAccessStrategy { - public static PropertyAccessStrategyEnhancedImpl with(AccessType getterAccessType) { - if ( getterAccessType == null ) { - return STANDARD; - } - - return switch ( getterAccessType ) { - case FIELD -> FIELD; - case PROPERTY -> PROPERTY; - }; + public static PropertyAccessStrategy with(AccessType getterAccessType) { + return getterAccessType == null + ? STANDARD + : switch ( getterAccessType ) { + case FIELD -> FIELD; + case PROPERTY -> PROPERTY; + }; } private final @Nullable AccessType classAccessType; - public static PropertyAccessStrategyEnhancedImpl STANDARD = new PropertyAccessStrategyEnhancedImpl( null ); - public static PropertyAccessStrategyEnhancedImpl FIELD = new PropertyAccessStrategyEnhancedImpl( AccessType.FIELD ); - public static PropertyAccessStrategyEnhancedImpl PROPERTY = new PropertyAccessStrategyEnhancedImpl( AccessType.PROPERTY ); + public static PropertyAccessStrategy STANDARD = new PropertyAccessStrategyEnhancedImpl( null ); + public static PropertyAccessStrategy FIELD = new PropertyAccessStrategyEnhancedImpl( AccessType.FIELD ); + public static PropertyAccessStrategy PROPERTY = new PropertyAccessStrategyEnhancedImpl( AccessType.PROPERTY ); public PropertyAccessStrategyEnhancedImpl(@Nullable AccessType classAccessType) { this.classAccessType = classAccessType; diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyFieldImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyFieldImpl.java index 6290b01b18fb..15208a784923 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyFieldImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyFieldImpl.java @@ -17,7 +17,7 @@ public class PropertyAccessStrategyFieldImpl implements PropertyAccessStrategy { /** * Singleton access */ - public static final PropertyAccessStrategyFieldImpl INSTANCE = new PropertyAccessStrategyFieldImpl(); + public static final PropertyAccessStrategy INSTANCE = new PropertyAccessStrategyFieldImpl(); @Override public PropertyAccess buildPropertyAccess(Class containerJavaType, String propertyName, boolean setterRequired) { diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyGetterImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyGetterImpl.java index 901d7ce678f2..b27f0e96f766 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyGetterImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyGetterImpl.java @@ -16,7 +16,7 @@ public class PropertyAccessStrategyGetterImpl implements PropertyAccessStrategy /** * Singleton access */ - public static final PropertyAccessStrategyGetterImpl INSTANCE = new PropertyAccessStrategyGetterImpl(); + public static final PropertyAccessStrategy INSTANCE = new PropertyAccessStrategyGetterImpl(); @Override public PropertyAccess buildPropertyAccess(Class containerJavaType, String propertyName, boolean setterRequired) { diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyIndexBackRefImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyIndexBackRefImpl.java index 6580acf43f30..4249b204ad28 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyIndexBackRefImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyIndexBackRefImpl.java @@ -74,9 +74,8 @@ public Object get(Object owner) { return PropertyAccessStrategyBackRefImpl.UNKNOWN; } - @SuppressWarnings("rawtypes") @Override - public Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { + public Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { return session.getPersistenceContextInternal().getIndexInOwner( entityName, propertyName, owner, mergeMap ); } @@ -110,7 +109,7 @@ private static class SetterImpl implements Setter { /** * Singleton access */ - public static final SetterImpl INSTANCE = new SetterImpl(); + public static final Setter INSTANCE = new SetterImpl(); @Override public void set(Object target, @Nullable Object value) { diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyMapImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyMapImpl.java index 6c9687689f86..2ea9d11a6db3 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyMapImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyMapImpl.java @@ -19,7 +19,7 @@ public class PropertyAccessStrategyMapImpl implements PropertyAccessStrategy { /** * Singleton access */ - public static final PropertyAccessStrategyMapImpl INSTANCE = new PropertyAccessStrategyMapImpl(); + public static final PropertyAccessStrategy INSTANCE = new PropertyAccessStrategyMapImpl(); @Override public PropertyAccess buildPropertyAccess(@Nullable Class containerJavaType, String propertyName, boolean setterRequired) { diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyMixedImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyMixedImpl.java index f099b4c8f853..b485a1daf433 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyMixedImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyMixedImpl.java @@ -16,7 +16,7 @@ public class PropertyAccessStrategyMixedImpl implements PropertyAccessStrategy { /** * Singleton access */ - public static final PropertyAccessStrategyMixedImpl INSTANCE = new PropertyAccessStrategyMixedImpl(); + public static final PropertyAccessStrategy INSTANCE = new PropertyAccessStrategyMixedImpl(); @Override public PropertyAccess buildPropertyAccess(Class containerJavaType, String propertyName, boolean setterRequired) { diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyNoopImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyNoopImpl.java index b4a104e63d2b..62fdbb209956 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyNoopImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyNoopImpl.java @@ -26,7 +26,7 @@ public class PropertyAccessStrategyNoopImpl implements PropertyAccessStrategy { /** * Singleton access */ - public static final PropertyAccessStrategyNoopImpl INSTANCE = new PropertyAccessStrategyNoopImpl(); + public static final PropertyAccessStrategy INSTANCE = new PropertyAccessStrategyNoopImpl(); @Override public PropertyAccess buildPropertyAccess(Class containerJavaType, String propertyName, boolean setterRequired) { @@ -67,8 +67,7 @@ private static class GetterImpl implements Getter { } @Override - @SuppressWarnings("rawtypes") - public @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { + public @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { return null; } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyResolverStandardImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyResolverStandardImpl.java index 268180906258..e9724aeb8082 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyResolverStandardImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyResolverStandardImpl.java @@ -6,8 +6,6 @@ import org.hibernate.HibernateException; import org.hibernate.boot.registry.selector.spi.StrategySelector; -import org.hibernate.boot.spi.AccessType; -import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.RepresentationMode; import org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies; import org.hibernate.property.access.spi.PropertyAccessStrategy; @@ -15,6 +13,11 @@ import org.hibernate.service.ServiceRegistry; import static org.hibernate.engine.internal.ManagedTypeHelper.isManagedType; +import static org.hibernate.internal.util.StringHelper.isNotEmpty; +import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.BASIC; +import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.FIELD; +import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.MAP; +import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.MIXED; /** * Standard implementation of PropertyAccessStrategyResolver @@ -34,42 +37,35 @@ public PropertyAccessStrategy resolvePropertyAccessStrategy( String explicitAccessStrategyName, RepresentationMode representationMode) { - if ( BuiltInPropertyAccessStrategies.BASIC.getExternalName().equals( explicitAccessStrategyName ) - || BuiltInPropertyAccessStrategies.FIELD.getExternalName().equals( explicitAccessStrategyName ) - || BuiltInPropertyAccessStrategies.MIXED.getExternalName().equals( explicitAccessStrategyName ) ) { - //type-cache-pollution agent: it's crucial to use the ManagedTypeHelper rather than attempting a direct cast - if ( isManagedType( containerClass ) ) { - if ( AccessType.FIELD.getType().equals( explicitAccessStrategyName ) ) { - return PropertyAccessStrategyEnhancedImpl.FIELD; - } - else if ( AccessType.PROPERTY.getType().equals( explicitAccessStrategyName ) ) { - return PropertyAccessStrategyEnhancedImpl.PROPERTY; - } + if ( isManagedType( containerClass ) ) { + if ( BASIC.getExternalName().equals( explicitAccessStrategyName ) ) { + return PropertyAccessStrategyEnhancedImpl.PROPERTY; + } + else if ( FIELD.getExternalName().equals( explicitAccessStrategyName ) ) { + return PropertyAccessStrategyEnhancedImpl.FIELD; + } + else if ( MIXED.getExternalName().equals( explicitAccessStrategyName ) ) { return PropertyAccessStrategyEnhancedImpl.STANDARD; } } - if ( StringHelper.isNotEmpty( explicitAccessStrategyName ) ) { + if ( isNotEmpty( explicitAccessStrategyName ) ) { return resolveExplicitlyNamedPropertyAccessStrategy( explicitAccessStrategyName ); } - - if ( representationMode == RepresentationMode.MAP ) { - return BuiltInPropertyAccessStrategies.MAP.getStrategy(); + else if ( representationMode == RepresentationMode.MAP ) { + return MAP.getStrategy(); } else { - return BuiltInPropertyAccessStrategies.BASIC.getStrategy(); + return BASIC.getStrategy(); } } protected PropertyAccessStrategy resolveExplicitlyNamedPropertyAccessStrategy(String explicitAccessStrategyName) { - final BuiltInPropertyAccessStrategies builtInStrategyEnum = BuiltInPropertyAccessStrategies.interpret( - explicitAccessStrategyName - ); - if ( builtInStrategyEnum != null ) { - return builtInStrategyEnum.getStrategy(); - } + final var builtInStrategyEnum = BuiltInPropertyAccessStrategies.interpret( explicitAccessStrategyName ); + return builtInStrategyEnum != null + ? builtInStrategyEnum.getStrategy() + : strategySelectorService().resolveStrategy( PropertyAccessStrategy.class, explicitAccessStrategyName ); - return strategySelectorService().resolveStrategy( PropertyAccessStrategy.class, explicitAccessStrategyName ); } private StrategySelector strategySelectorService; diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/BuiltInPropertyAccessStrategies.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/BuiltInPropertyAccessStrategies.java index 3071087f4472..8143bae6bcf9 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/BuiltInPropertyAccessStrategies.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/BuiltInPropertyAccessStrategies.java @@ -19,32 +19,38 @@ * @author Steve Ebersole */ public enum BuiltInPropertyAccessStrategies { - BASIC( "property", PropertyAccessStrategyBasicImpl.INSTANCE ), - FIELD( "field", PropertyAccessStrategyFieldImpl.INSTANCE ), - MIXED( "mixed", PropertyAccessStrategyMixedImpl.INSTANCE ), - MAP( "map", PropertyAccessStrategyMapImpl.INSTANCE ), - EMBEDDED( "embedded", PropertyAccessStrategyEmbeddedImpl.INSTANCE ), - NOOP( "noop", PropertyAccessStrategyNoopImpl.INSTANCE ); - - private final String externalName; - private final PropertyAccessStrategy strategy; - - BuiltInPropertyAccessStrategies(String externalName, PropertyAccessStrategy strategy) { - this.externalName = externalName; - this.strategy = strategy; - } + BASIC, + FIELD, + MIXED, + MAP, + EMBEDDED, + NOOP; public String getExternalName() { - return externalName; + return switch ( this ) { + case BASIC -> "property"; + case FIELD -> "field"; + case MIXED -> "mixed"; + case MAP -> "map"; + case EMBEDDED -> "embedded"; + case NOOP -> "noop"; + }; } public PropertyAccessStrategy getStrategy() { - return strategy; + return switch ( this ) { + case BASIC -> PropertyAccessStrategyBasicImpl.INSTANCE; + case FIELD -> PropertyAccessStrategyFieldImpl.INSTANCE; + case MIXED -> PropertyAccessStrategyMixedImpl.INSTANCE; + case MAP -> PropertyAccessStrategyMapImpl.INSTANCE; + case EMBEDDED -> PropertyAccessStrategyEmbeddedImpl.INSTANCE; + case NOOP -> PropertyAccessStrategyNoopImpl.INSTANCE; + }; } public static @Nullable BuiltInPropertyAccessStrategies interpret(String name) { - for ( BuiltInPropertyAccessStrategies strategy : values() ) { - if ( strategy.externalName.equals( name ) ) { + for ( var strategy : values() ) { + if ( strategy.getExternalName().equals( name ) ) { return strategy; } } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterImpl.java index d9691959890a..3bd544cd8fa0 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterImpl.java @@ -4,16 +4,17 @@ */ package org.hibernate.property.access.spi; +import java.io.Serial; import java.io.Serializable; import java.lang.reflect.Field; import org.hibernate.Internal; import org.hibernate.property.access.internal.AbstractFieldSerialForm; -import org.hibernate.property.access.internal.AccessStrategyHelper; import org.checkerframework.checker.nullness.qual.Nullable; import static org.hibernate.property.access.internal.AccessStrategyHelper.determineEnhancementState; +import static org.hibernate.property.access.internal.AccessStrategyHelper.handleEnhancedInjection; /** * A specialized Setter implementation for handling setting values into @@ -38,13 +39,14 @@ public EnhancedSetterImpl(Class containerClass, String propertyName, Field fi @Override public void set(Object target, @Nullable Object value) { super.set( target, value ); - AccessStrategyHelper.handleEnhancedInjection( target, value, enhancementState, propertyName ); + handleEnhancedInjection( target, value, enhancementState, propertyName ); } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // serialization + @Serial private Object writeReplace() { return new SerialForm( getContainerClass(), propertyName, getField() ); } @@ -60,6 +62,7 @@ private SerialForm(Class containerClass, String propertyName, Field field) { this.propertyName = propertyName; } + @Serial private Object readResolve() { return new EnhancedSetterImpl( containerClass, propertyName, resolveField() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterMethodImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterMethodImpl.java index f67e74f377c9..ca60fca711fb 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterMethodImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterMethodImpl.java @@ -4,16 +4,17 @@ */ package org.hibernate.property.access.spi; +import java.io.Serial; import java.io.Serializable; import java.lang.reflect.Method; import org.hibernate.Internal; import org.hibernate.property.access.internal.AbstractSetterMethodSerialForm; -import org.hibernate.property.access.internal.AccessStrategyHelper; import org.checkerframework.checker.nullness.qual.Nullable; import static org.hibernate.property.access.internal.AccessStrategyHelper.determineEnhancementState; +import static org.hibernate.property.access.internal.AccessStrategyHelper.handleEnhancedInjection; /** * A specialized Setter implementation for handling setting values into a bytecode-enhanced Class @@ -38,13 +39,14 @@ public EnhancedSetterMethodImpl(Class containerClass, String propertyName, Me public void set(Object target, @Nullable Object value) { super.set( target, value ); - AccessStrategyHelper.handleEnhancedInjection( target, value, enhancementState, propertyName ); + handleEnhancedInjection( target, value, enhancementState, propertyName ); } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // serialization + @Serial private Object writeReplace() { return new SerialForm( getContainerClass(), propertyName, getMethod() ); } @@ -54,6 +56,7 @@ private SerialForm(Class containerClass, String propertyName, Method method) super( containerClass, propertyName, method ); } + @Serial private Object readResolve() { return new EnhancedSetterMethodImpl( getContainerClass(), getPropertyName(), resolveMethod() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/Getter.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/Getter.java index f346dfec2ef2..6218e1fe175f 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/Getter.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/Getter.java @@ -39,7 +39,7 @@ public interface Getter extends Serializable { * * @return The extracted value. */ - @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session); + @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session); /** * Retrieve the declared Java type class diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/GetterFieldImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/GetterFieldImpl.java index ce38338e902f..399006e19721 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/GetterFieldImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/GetterFieldImpl.java @@ -5,6 +5,7 @@ package org.hibernate.property.access.spi; import java.io.ObjectStreamException; +import java.io.Serial; import java.io.Serializable; import java.lang.reflect.Field; import java.lang.reflect.Member; @@ -15,11 +16,12 @@ import org.hibernate.Internal; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.internal.util.ReflectHelper; import org.hibernate.property.access.internal.AbstractFieldSerialForm; import org.checkerframework.checker.nullness.qual.Nullable; +import static org.hibernate.internal.util.ReflectHelper.findGetterMethodForFieldAccess; + /** * Field-based implementation of Getter * @@ -33,7 +35,7 @@ public class GetterFieldImpl implements Getter { private final @Nullable Method getterMethod; public GetterFieldImpl(Class containerClass, String propertyName, Field field) { - this ( containerClass, propertyName, field, ReflectHelper.findGetterMethodForFieldAccess( field, propertyName ) ); + this ( containerClass, propertyName, field, findGetterMethodForFieldAccess( field, propertyName ) ); } GetterFieldImpl(Class containerClass, String propertyName, Field field, Method getterMethod) { @@ -63,9 +65,8 @@ public GetterFieldImpl(Class containerClass, String propertyName, Field field } } - @SuppressWarnings("rawtypes") @Override - public @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { + public @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { return get( owner ); } @@ -98,6 +99,7 @@ public Member getMember() { return getterMethod; } + @Serial private Object writeReplace() throws ObjectStreamException { return new SerialForm( containerClass, propertyName, field ); } @@ -112,6 +114,7 @@ private SerialForm(Class containerClass, String propertyName, Field field) { this.propertyName = propertyName; } + @Serial private Object readResolve() { return new GetterFieldImpl( containerClass, propertyName, resolveField() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/GetterMethodImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/GetterMethodImpl.java index ea74a763b5d8..c60082ad9300 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/GetterMethodImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/GetterMethodImpl.java @@ -5,6 +5,7 @@ package org.hibernate.property.access.spi; import java.io.ObjectStreamException; +import java.io.Serial; import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Member; @@ -81,9 +82,8 @@ public GetterMethodImpl(Class containerClass, String propertyName, Method get } } - @SuppressWarnings("rawtypes") @Override - public @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { + public @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { return get( owner ); } @@ -112,6 +112,7 @@ public Method getMethod() { return getterMethod; } + @Serial private Object writeReplace() throws ObjectStreamException { return new SerialForm( containerClass, propertyName, getterMethod ); } @@ -130,6 +131,7 @@ private SerialForm(Class containerClass, String propertyName, Method method) this.methodName = method.getName(); } + @Serial private Object readResolve() { return new GetterMethodImpl( containerClass, propertyName, resolveMethod() ); } @@ -142,7 +144,7 @@ private Method resolveMethod() { } catch (NoSuchMethodException e) { throw new PropertyAccessSerializationException( - "Unable to resolve getter method on deserialization : " + declaringClass.getName() + "#" + methodName + "Unable to resolve getter method on deserialization: " + declaringClass.getName() + "#" + methodName ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterFieldImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterFieldImpl.java index f332c54cb4c1..9c33bbdb6f6c 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterFieldImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterFieldImpl.java @@ -4,6 +4,7 @@ */ package org.hibernate.property.access.spi; +import java.io.Serial; import java.io.Serializable; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -11,13 +12,14 @@ import org.hibernate.Internal; import org.hibernate.PropertyAccessException; -import org.hibernate.internal.util.ReflectHelper; import org.hibernate.property.access.internal.AbstractFieldSerialForm; import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.LazyInitializer; import org.checkerframework.checker.nullness.qual.Nullable; +import static org.hibernate.internal.util.ReflectHelper.setterMethodOrNull; + /** * Field-based implementation of Setter * @@ -34,7 +36,7 @@ public SetterFieldImpl(Class containerClass, String propertyName, Field field this.containerClass = containerClass; this.propertyName = propertyName; this.field = field; - this.setterMethod = ReflectHelper.setterMethodOrNull( containerClass, propertyName, field.getType() ); + this.setterMethod = setterMethodOrNull( containerClass, propertyName, field.getType() ); } public Class getContainerClass() { @@ -106,6 +108,7 @@ else if ( value != null ) { return setterMethod; } + @Serial private Object writeReplace() { return new SerialForm( containerClass, propertyName, field ); } @@ -121,6 +124,7 @@ private SerialForm(Class containerClass, String propertyName, Field field) { this.propertyName = propertyName; } + @Serial private Object readResolve() { return new SetterFieldImpl( containerClass, propertyName, resolveField() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterMethodImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterMethodImpl.java index 58751bfe2562..52bdddf23405 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterMethodImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterMethodImpl.java @@ -4,6 +4,7 @@ */ package org.hibernate.property.access.spi; +import java.io.Serial; import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -128,6 +129,7 @@ public Method getMethod() { return setterMethod; } + @Serial private Object writeReplace() { return new SerialForm( containerClass, propertyName, setterMethod ); } @@ -137,6 +139,7 @@ private SerialForm(Class containerClass, String propertyName, Method method) super( containerClass, propertyName, method ); } + @Serial private Object readResolve() { return new SetterMethodImpl( getContainerClass(), getPropertyName(), resolveMethod() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/PropertyFactory.java b/hibernate-core/src/main/java/org/hibernate/tuple/PropertyFactory.java index ea51dbea8405..ddaa61cdb263 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/PropertyFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/PropertyFactory.java @@ -94,9 +94,9 @@ public static VersionProperty buildVersionProperty( new BaselineAttributeInformation.Builder() .setLazy( lazy ) .setInsertable( property.isInsertable() ) - .setUpdateable( property.isUpdateable() ) + .setUpdateable( property.isUpdatable() ) .setNullable( property.isOptional() ) - .setDirtyCheckable( property.isUpdateable() && !lazy ) + .setDirtyCheckable( property.isUpdatable() && !lazy ) .setVersionable( property.isOptimisticLocked() ) .setCascadeStyle( property.getCascadeStyle() ) .setOnDeleteAction( property.getOnDeleteAction() ) @@ -165,9 +165,9 @@ public static NonIdentifierAttribute buildEntityBasedAttribute( new BaselineAttributeInformation.Builder() .setLazy( lazy ) .setInsertable( property.isInsertable() ) - .setUpdateable( property.isUpdateable() ) + .setUpdateable( property.isUpdatable() ) .setNullable( property.isOptional() ) - .setDirtyCheckable( alwaysDirtyCheck || property.isUpdateable() ) + .setDirtyCheckable( alwaysDirtyCheck || property.isUpdatable() ) .setVersionable( property.isOptimisticLocked() ) .setCascadeStyle( property.getCascadeStyle() ) .setOnDeleteAction( property.getOnDeleteAction() ) @@ -185,9 +185,9 @@ public static NonIdentifierAttribute buildEntityBasedAttribute( new BaselineAttributeInformation.Builder() .setLazy( lazy ) .setInsertable( property.isInsertable() ) - .setUpdateable( property.isUpdateable() ) + .setUpdateable( property.isUpdatable() ) .setNullable( property.isOptional() ) - .setDirtyCheckable( alwaysDirtyCheck || property.isUpdateable() ) + .setDirtyCheckable( alwaysDirtyCheck || property.isUpdatable() ) .setVersionable( property.isOptimisticLocked() ) .setCascadeStyle( property.getCascadeStyle() ) .setOnDeleteAction( property.getOnDeleteAction() ) @@ -207,9 +207,9 @@ public static NonIdentifierAttribute buildEntityBasedAttribute( new BaselineAttributeInformation.Builder() .setLazy( lazy ) .setInsertable( property.isInsertable() ) - .setUpdateable( property.isUpdateable() ) + .setUpdateable( property.isUpdatable() ) .setNullable( property.isOptional() ) - .setDirtyCheckable( alwaysDirtyCheck || property.isUpdateable() ) + .setDirtyCheckable( alwaysDirtyCheck || property.isUpdatable() ) .setVersionable( property.isOptimisticLocked() ) .setCascadeStyle( property.getCascadeStyle() ) .setOnDeleteAction( property.getOnDeleteAction() ) diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java index f822c2136a3c..29aafc2ef259 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java @@ -287,7 +287,7 @@ public EntityMetamodel( if ( property.isNaturalIdentifier() ) { verifyNaturalIdProperty( property ); naturalIdNumbers.add( i ); - if ( property.isUpdateable() ) { + if ( property.isUpdatable() ) { foundUpdateableNaturalIdProperty = true; } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/AttributeAccessorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/AttributeAccessorTest.java index 3baa787d95ad..3123980de208 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/AttributeAccessorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/access/AttributeAccessorTest.java @@ -22,7 +22,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Chris Cranford @@ -93,7 +93,7 @@ public void setName(String name) { public static class BasicAttributeAccessor extends PropertyAccessStrategyBasicImpl { @Override - public PropertyAccess buildPropertyAccess(Class containerJavaType, String propertyName, boolean setterRequired) { + public PropertyAccess buildPropertyAccess(Class containerJavaType, String propertyName, boolean setterRequired) { return super.buildPropertyAccess( containerJavaType, propertyName, setterRequired ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/lazy/cache/UninitializedAssociationsInCacheTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/lazy/cache/UninitializedAssociationsInCacheTest.java index 24f60085f712..ba51d38be4a3 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/lazy/cache/UninitializedAssociationsInCacheTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/lazy/cache/UninitializedAssociationsInCacheTest.java @@ -7,10 +7,8 @@ import java.util.ArrayList; import java.util.List; -import org.hibernate.Hibernate; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.proxy.HibernateProxy; import org.hibernate.stat.CacheRegionStatistics; @@ -21,7 +19,7 @@ import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.Setting; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import jakarta.persistence.Basic; @@ -36,11 +34,16 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hibernate.Hibernate.isInitialized; +import static org.hibernate.Hibernate.isPropertyInitialized; +import static org.hibernate.cfg.CacheSettings.USE_SECOND_LEVEL_CACHE; +import static org.hibernate.cfg.StatisticsSettings.GENERATE_STATISTICS; +import static org.hibernate.cfg.TransactionSettings.ENABLE_LAZY_LOAD_NO_TRANS; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -@SuppressWarnings("JUnitMalformedDeclaration") @DomainModel( annotatedClasses = { UninitializedAssociationsInCacheTest.Employee.class @@ -48,9 +51,9 @@ ) @ServiceRegistry( settings = { - @Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true" ), - @Setting( name = AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, value = "false" ), - @Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ), + @Setting( name = USE_SECOND_LEVEL_CACHE, value = "true" ), + @Setting( name = ENABLE_LAZY_LOAD_NO_TRANS, value = "false" ), + @Setting( name = GENERATE_STATISTICS, value = "true" ), } ) @SessionFactory( @@ -87,26 +90,26 @@ public void attributeLoadingFromCache(SessionFactoryScope scope) { scope.inTransaction( (s) -> { final Employee boss = s.find( Employee.class, 1 ); - Assert.assertEquals( "boss", boss.regularString ); + assertEquals( "boss", boss.regularString ); final Employee leader = s.find( Employee.class, 2 ); - Assert.assertEquals( "leader", leader.regularString ); + assertEquals( "leader", leader.regularString ); final Employee member = s.find( Employee.class, 3 ); - Assert.assertEquals( "member", member.regularString ); + assertEquals( "member", member.regularString ); - assertTrue( Hibernate.isPropertyInitialized( boss, "superior" ) ); - assertTrue( Hibernate.isInitialized( boss.superior ) ); + assertTrue( isPropertyInitialized( boss, "superior" ) ); + assertTrue( isInitialized( boss.superior ) ); assertThat( boss.superior, not( instanceOf( HibernateProxy.class ) ) ); - Assert.assertFalse( Hibernate.isPropertyInitialized( boss, "subordinates" ) ); + assertFalse( isPropertyInitialized( boss, "subordinates" ) ); - assertTrue( Hibernate.isPropertyInitialized( leader, "superior" ) ); - assertTrue( Hibernate.isInitialized( leader.superior ) ); + assertTrue( isPropertyInitialized( leader, "superior" ) ); + assertTrue( isInitialized( leader.superior ) ); assertThat( leader.superior, not( instanceOf( HibernateProxy.class ) ) ); - Assert.assertFalse( Hibernate.isPropertyInitialized( leader, "subordinates" ) ); + assertFalse( isPropertyInitialized( leader, "subordinates" ) ); - assertTrue( Hibernate.isPropertyInitialized( member, "superior" ) ); - assertTrue( Hibernate.isInitialized( member.superior ) ); + assertTrue( isPropertyInitialized( member, "superior" ) ); + assertTrue( isInitialized( member.superior ) ); assertThat( member.superior, not( instanceOf( HibernateProxy.class ) ) ); - Assert.assertFalse( Hibernate.isPropertyInitialized( member, "subordinates" ) ); + assertFalse( isPropertyInitialized( member, "subordinates" ) ); } ); @@ -119,29 +122,29 @@ public void attributeLoadingFromCache(SessionFactoryScope scope) { final Employee boss = s.find( Employee.class, 1 ); final Employee leader = s.find( Employee.class, 2 ); final Employee member = s.find( Employee.class, 3 ); - Assert.assertTrue( Hibernate.isPropertyInitialized( boss, "superior" ) ); - Assert.assertFalse( Hibernate.isPropertyInitialized( boss, "subordinates" ) ); - - Assert.assertTrue( Hibernate.isPropertyInitialized( member, "superior" ) ); - Assert.assertFalse( Hibernate.isPropertyInitialized( member, "subordinates" ) ); - Assert.assertNull( boss.superior ); - - assertTrue( Hibernate.isPropertyInitialized( boss, "superior" ) ); - Assert.assertFalse( Hibernate.isPropertyInitialized( boss, "subordinates" ) ); - Assert.assertEquals( leader, boss.subordinates.iterator().next() ); - assertTrue( Hibernate.isPropertyInitialized( boss, "subordinates" ) ); - - Assert.assertTrue( Hibernate.isPropertyInitialized( leader, "superior" ) ); - Assert.assertFalse( Hibernate.isPropertyInitialized( leader, "subordinates" ) ); - Assert.assertEquals( boss, leader.superior ); - Assert.assertEquals( member, leader.subordinates.iterator().next() ); - assertTrue( Hibernate.isPropertyInitialized( leader, "subordinates" ) ); - - Assert.assertTrue( Hibernate.isPropertyInitialized( member, "superior" ) ); - Assert.assertFalse( Hibernate.isPropertyInitialized( member, "subordinates" ) ); - Assert.assertEquals( leader, member.superior ); + assertTrue( isPropertyInitialized( boss, "superior" ) ); + assertFalse( isPropertyInitialized( boss, "subordinates" ) ); + + assertTrue( isPropertyInitialized( member, "superior" ) ); + assertFalse( isPropertyInitialized( member, "subordinates" ) ); + Assertions.assertNull( boss.superior ); + + assertTrue( isPropertyInitialized( boss, "superior" ) ); + assertFalse( isPropertyInitialized( boss, "subordinates" ) ); + assertEquals( leader, boss.subordinates.iterator().next() ); + assertTrue( isPropertyInitialized( boss, "subordinates" ) ); + + assertTrue( isPropertyInitialized( leader, "superior" ) ); + assertFalse( isPropertyInitialized( leader, "subordinates" ) ); + assertEquals( boss, leader.superior ); + assertEquals( member, leader.subordinates.iterator().next() ); + assertTrue( isPropertyInitialized( leader, "subordinates" ) ); + + assertTrue( isPropertyInitialized( member, "superior" ) ); + assertFalse( isPropertyInitialized( member, "subordinates" ) ); + assertEquals( leader, member.superior ); assertTrue( member.subordinates.isEmpty() ); - assertTrue( Hibernate.isPropertyInitialized( member, "subordinates" ) ); + assertTrue( isPropertyInitialized( member, "subordinates" ) ); } ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/WrapperArrayHandlingDisallowTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/WrapperArrayHandlingDisallowTests.java index 64dacf023ac3..b06bdae0ef69 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/WrapperArrayHandlingDisallowTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/WrapperArrayHandlingDisallowTests.java @@ -19,6 +19,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests for mapping wrapper values @@ -35,8 +36,8 @@ public void verifyByteArrayMappings(SessionFactoryScope scope) { } catch (Exception e) { final Throwable rootCause = ExceptionHelper.getRootCause( e ); - Assertions.assertEquals( MappingException.class, rootCause.getClass() ); - assertThat( rootCause.getMessage(), containsString( WrapperArrayHandlingDisallowTests.EntityOfByteArrays.class.getName() + "#wrapper" ) ); + assertEquals( MappingException.class, rootCause.getClass() ); + assertThat( rootCause.getMessage(), containsString( WrapperArrayHandlingDisallowTests.EntityOfByteArrays.class.getName() + ".wrapper" ) ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/attribute/BasicAttributeMutabilityTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/attribute/BasicAttributeMutabilityTests.java index 5232e0dc3ac3..44e7ff7352ea 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/attribute/BasicAttributeMutabilityTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/attribute/BasicAttributeMutabilityTests.java @@ -58,13 +58,13 @@ public void verifyDomainModel(DomainModelScope domainModelScope, SessionFactoryS // `@Immutable` final Property theDateProperty = persistentClass.getProperty( "theDate" ); - assertThat( theDateProperty.isUpdateable() ).isFalse(); + assertThat( theDateProperty.isUpdatable() ).isFalse(); final AttributeMapping theDateAttribute = entityDescriptor.findAttributeMapping( "theDate" ); assertThat( theDateAttribute.getExposedMutabilityPlan().isMutable() ).isFalse(); // `@Mutability(Immutability.class)` final Property anotherDateProperty = persistentClass.getProperty( "anotherDate" ); - assertThat( anotherDateProperty.isUpdateable() ).isTrue(); + assertThat( anotherDateProperty.isUpdatable() ).isTrue(); final AttributeMapping anotherDateAttribute = entityDescriptor.findAttributeMapping( "anotherDate" ); assertThat( anotherDateAttribute.getExposedMutabilityPlan().isMutable() ).isFalse(); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/attribute/EntityAttributeMutabilityTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/attribute/EntityAttributeMutabilityTest.java index 7e54fd69aec7..3a2190137a43 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/attribute/EntityAttributeMutabilityTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/attribute/EntityAttributeMutabilityTest.java @@ -50,13 +50,13 @@ public void verifyMetamodel(DomainModelScope domainModelScope, SessionFactorySco // `@Immutable` final Property managerProperty = persistentClass.getProperty( "manager" ); - assertThat( managerProperty.isUpdateable() ).isFalse(); + assertThat( managerProperty.isUpdatable() ).isFalse(); final AttributeMapping managerAttribute = entityDescriptor.findAttributeMapping( "manager" ); assertThat( managerAttribute.getExposedMutabilityPlan().isMutable() ).isFalse(); // `@Mutability(Immutability.class)` - no effect final Property manager2Property = persistentClass.getProperty( "manager2" ); - assertThat( manager2Property.isUpdateable() ).isTrue(); + assertThat( manager2Property.isUpdatable() ).isTrue(); final AttributeMapping manager2Attribute = entityDescriptor.findAttributeMapping( "manager2" ); assertThat( manager2Attribute.getExposedMutabilityPlan().isMutable() ).isTrue(); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/attribute/ImmutabilityMapAsBasicTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/attribute/ImmutabilityMapAsBasicTests.java index 248d6f7f752e..8291930175b9 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/attribute/ImmutabilityMapAsBasicTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/attribute/ImmutabilityMapAsBasicTests.java @@ -46,7 +46,7 @@ public class ImmutabilityMapAsBasicTests { void verifyMetamodel(DomainModelScope domainModelScope, SessionFactoryScope sessionFactoryScope) { domainModelScope.withHierarchy( TestEntity.class, (entity) -> { final Property property = entity.getProperty( "data" ); - assertThat( property.isUpdateable() ).isTrue(); + assertThat( property.isUpdatable() ).isTrue(); final BasicValue value = (BasicValue) property.getValue(); final BasicValue.Resolution resolution = value.resolve(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/attribute/ImmutableMapAsBasicTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/attribute/ImmutableMapAsBasicTests.java index 2868e4a92f78..5642b9ad8f02 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/attribute/ImmutableMapAsBasicTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/attribute/ImmutableMapAsBasicTests.java @@ -64,7 +64,7 @@ void verifyMetamodel(DomainModelScope domainModelScope, SessionFactoryScope sess .getEntityDescriptor( TestEntity.class ); final Property property = persistentClass.getProperty( "data" ); - assertThat( property.isUpdateable() ).isFalse(); + assertThat( property.isUpdatable() ).isFalse(); final BasicValue value = (BasicValue) property.getValue(); final BasicValue.Resolution resolution = value.resolve(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/converted/ImmutabilityConverterTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/converted/ImmutabilityConverterTests.java index a775a6fbc66e..849c495909bf 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/converted/ImmutabilityConverterTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/converted/ImmutabilityConverterTests.java @@ -41,7 +41,7 @@ void verifyMetamodel(DomainModelScope scope) { scope.withHierarchy( TestEntity.class, (entity) -> { final Property theDateProperty = entity.getProperty( "theDate" ); assertThat( theDateProperty ).isNotNull(); - assertThat( theDateProperty.isUpdateable() ).isTrue(); + assertThat( theDateProperty.isUpdatable() ).isTrue(); final BasicValue basicValue = (BasicValue) theDateProperty.getValue(); final BasicValue.Resolution resolution = basicValue.resolve(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/converted/ImmutableConvertedBaselineTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/converted/ImmutableConvertedBaselineTests.java index ab89b2adc7e9..b811d73c914a 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/converted/ImmutableConvertedBaselineTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/converted/ImmutableConvertedBaselineTests.java @@ -61,13 +61,13 @@ void verifyDomainModel(DomainModelScope domainModelScope, SessionFactoryScope sf // `@Immutable` final Property theDateProperty = persistentClass.getProperty( "theDate" ); - assertThat( theDateProperty.isUpdateable() ).isFalse(); + assertThat( theDateProperty.isUpdatable() ).isFalse(); final AttributeMapping theDateAttribute = entityDescriptor.findAttributeMapping( "theDate" ); assertThat( theDateAttribute.getExposedMutabilityPlan().isMutable() ).isFalse(); // `@Mutability(Immutability.class)` final Property anotherDateProperty = persistentClass.getProperty( "anotherDate" ); - assertThat( anotherDateProperty.isUpdateable() ).isTrue(); + assertThat( anotherDateProperty.isUpdatable() ).isTrue(); final AttributeMapping anotherDateAttribute = entityDescriptor.findAttributeMapping( "anotherDate" ); assertThat( anotherDateAttribute.getExposedMutabilityPlan().isMutable() ).isFalse(); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/converted/ImmutableConverterTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/converted/ImmutableConverterTests.java index 5675c0a89d17..3a4520c82463 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/converted/ImmutableConverterTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/mutability/converted/ImmutableConverterTests.java @@ -44,7 +44,7 @@ void verifyMetamodel(DomainModelScope scope) { { final Property property = entity.getProperty( "mutableDate" ); assertThat( property ).isNotNull(); - assertThat( property.isUpdateable() ).isTrue(); + assertThat( property.isUpdatable() ).isTrue(); final BasicValue basicValue = (BasicValue) property.getValue(); final BasicValue.Resolution resolution = basicValue.resolve(); @@ -54,7 +54,7 @@ void verifyMetamodel(DomainModelScope scope) { { final Property property = entity.getProperty( "immutableDate" ); assertThat( property ).isNotNull(); - assertThat( property.isUpdateable() ).isTrue(); + assertThat( property.isUpdatable() ).isTrue(); final BasicValue basicValue = (BasicValue) property.getValue(); final BasicValue.Resolution resolution = basicValue.resolve(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/onetoone/OneToOneMapsIdChangeParentTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/onetoone/OneToOneMapsIdChangeParentTest.java index ea09c531f4ea..80177be7d89c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/onetoone/OneToOneMapsIdChangeParentTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/onetoone/OneToOneMapsIdChangeParentTest.java @@ -24,8 +24,8 @@ import java.lang.invoke.MethodHandles; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Vlad Mihalcea @@ -48,7 +48,7 @@ public class OneToOneMapsIdChangeParentTest { ) ); - private Triggerable triggerable = logInspection.watchForLogMessages( "HHH000502:" ); + private final Triggerable triggerable = logInspection.watchForLogMessages( "HHH000502:" ); @Test diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/property/BasicPropertyAccessorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/property/BasicPropertyAccessorTest.java index 98001bd38b50..28e54b0d9639 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/property/BasicPropertyAccessorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/property/BasicPropertyAccessorTest.java @@ -68,7 +68,7 @@ public void setIt(Object it) { @Test public void testBridgeMethodDisregarded() { - PropertyAccessStrategyBasicImpl accessStrategy = PropertyAccessStrategyBasicImpl.INSTANCE; + var accessStrategy = PropertyAccessStrategyBasicImpl.INSTANCE; { final PropertyAccess access = accessStrategy.buildPropertyAccess( Duper.class, "it", true ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/property/PropertyAccessStrategyMapTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/property/PropertyAccessStrategyMapTest.java index ba1ba49346c4..cd1df486f654 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/property/PropertyAccessStrategyMapTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/property/PropertyAccessStrategyMapTest.java @@ -31,7 +31,7 @@ public void testBasicNullClass() { @Test public void testNonMap() { - final PropertyAccessStrategyMapImpl accessStrategy = PropertyAccessStrategyMapImpl.INSTANCE; + final var accessStrategy = PropertyAccessStrategyMapImpl.INSTANCE; try { accessStrategy.buildPropertyAccess( Date.class, "time", true ); @@ -51,7 +51,7 @@ private void testBasic(final Class clazz) { final String key = "testKey"; final String value = "testValue"; - final PropertyAccessStrategyMapImpl accessStrategy = PropertyAccessStrategyMapImpl.INSTANCE; + final var accessStrategy = PropertyAccessStrategyMapImpl.INSTANCE; final PropertyAccess access = accessStrategy.buildPropertyAccess( clazz, key, true ); final HashMap map = new HashMap<>();