Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.boot.spi.PropertyData;
import org.hibernate.internal.log.DeprecationLogger;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.mapping.Any;
import org.hibernate.mapping.AttributeContainer;
Expand Down Expand Up @@ -882,9 +881,10 @@ static PropertyData getPropertyOverriddenByMapperOrMapsId(
final ClassDetailsRegistry classDetailsRegistry = buildingContext.getMetadataCollector()
.getSourceModelBuildingContext()
.getClassDetailsRegistry();
final String name = StringHelper.isEmpty( propertyHolder.getPersistentClass().getClassName() )
? propertyHolder.getPersistentClass().getEntityName()
: propertyHolder.getPersistentClass().getClassName();
final PersistentClass persistentClass = propertyHolder.getPersistentClass();
final String name = isEmpty( persistentClass.getClassName() )
? persistentClass.getEntityName()
: persistentClass.getClassName();
final ClassDetails classDetails = classDetailsRegistry.resolveClassDetails( name );
final InFlightMetadataCollector metadataCollector = buildingContext.getMetadataCollector();
if ( propertyHolder.isInIdClass() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ public interface IdentifierGenerator extends BeforeExecutionGenerator, Exportabl
* @param parameters param values, keyed by parameter name
* @param serviceRegistry Access to service that may be needed.
* @throws MappingException If configuration fails.
*
* @deprecated since it overrides a deprecated method
*/
@Override
@SuppressWarnings("removal")
@Override @Deprecated( since = "7.0", forRemoval = true )
default void configure(Type type, Properties parameters, ServiceRegistry serviceRegistry) {}

/**
Expand Down
61 changes: 33 additions & 28 deletions hibernate-core/src/main/java/org/hibernate/mapping/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
private PersistentClass owner;
private boolean dynamic;
private boolean isKey;
private Boolean isGeneric;
private transient Boolean isGeneric;
private String roleName;
private MappedSuperclass mappedSuperclass;
private Value discriminator;
Expand All @@ -97,7 +97,7 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
private String[] instantiatorPropertyNames;

// cache the status of the type
private volatile CompositeType type;
private transient volatile CompositeType type;

private AggregateColumn aggregateColumn;
private AggregateColumn parentAggregateColumn;
Expand Down Expand Up @@ -242,9 +242,7 @@ public List<Column> getAggregatedColumns() {

private void collectAggregatedColumns(List<Column> aggregatedColumns, Component component) {
for ( Property property : component.getProperties() ) {
final Value value = property.getValue();
if ( value instanceof Component ) {
final Component subComponent = (Component) value;
if ( property.getValue() instanceof Component subComponent ) {
final AggregateColumn subAggregate = subComponent.getAggregateColumn();
if ( subAggregate != null ) {
aggregatedColumns.add( subAggregate );
Expand All @@ -254,7 +252,7 @@ private void collectAggregatedColumns(List<Column> aggregatedColumns, Component
}
}
else {
aggregatedColumns.addAll( value.getColumns() );
aggregatedColumns.addAll( property.getValue().getColumns() );
}
}
if ( component.isPolymorphic() ) {
Expand All @@ -267,17 +265,16 @@ private void notifyPropertiesAboutAggregateColumn(AggregateColumn aggregateColum
// Let the BasicValue of every sub-column know about the aggregate,
// which is needed in type resolution
final Value value = property.getValue();
if ( value instanceof BasicValue ) {
assert ( (BasicValue) value ).getResolution() == null;
( (BasicValue) value ).setAggregateColumn( aggregateColumn );
if ( value instanceof BasicValue basicValue ) {
assert basicValue.getResolution() == null;
basicValue.setAggregateColumn( aggregateColumn );
}
else if ( value instanceof Component ) {
final Component subComponent = (Component) value;
else if ( value instanceof Component subComponent ) {
if ( subComponent.getAggregateColumn() == null ) {
subComponent.notifyPropertiesAboutAggregateColumn( aggregateColumn, subComponent );
}
else {
( (Component) value ).setParentAggregateColumn( aggregateColumn );
subComponent.setParentAggregateColumn( aggregateColumn );
}
}
}
Expand Down Expand Up @@ -678,11 +675,19 @@ private Generator buildIdentifierGenerator(Dialect dialect, RootClass rootClass)
if ( !value.getCustomIdGeneratorCreator().isAssigned() ) {
// skip any 'assigned' generators, they would have been
// handled by the StandardGenerationContextLocator
generator.addGeneratedValuePlan( new ValueGenerationPlan(
value.createGenerator( dialect, rootClass, property ),
getType().isMutable() ? injector( property, getAttributeDeclarer( rootClass ) ) : null,
i
) );
if ( value.createGenerator( dialect, rootClass, property )
instanceof BeforeExecutionGenerator beforeExecutionGenerator ) {
generator.addGeneratedValuePlan( new ValueGenerationPlan(
beforeExecutionGenerator,
getType().isMutable()
? injector( property, getAttributeDeclarer( rootClass ) )
: null,
i
) );
}
else {
throw new IdentifierGenerationException( "Identity generation isn't supported for composite ids" );
}
}
}
}
Expand Down Expand Up @@ -755,12 +760,12 @@ public Object locateGenerationContext(SharedSessionContractImplementor session,
}

public static class ValueGenerationPlan implements CompositeNestedGeneratedValueGenerator.GenerationPlan {
private final Generator subgenerator;
private final BeforeExecutionGenerator generator;
private final Setter injector;
private final int propertyIndex;

public ValueGenerationPlan(Generator subgenerator, Setter injector, int propertyIndex) {
this.subgenerator = subgenerator;
public ValueGenerationPlan(BeforeExecutionGenerator generator, Setter injector, int propertyIndex) {
this.generator = generator;
this.injector = injector;
this.propertyIndex = propertyIndex;
}
Expand All @@ -777,9 +782,8 @@ public int getPropertyIndex() {

@Override
public Object execute(SharedSessionContractImplementor session, Object incomingObject) {
if ( !subgenerator.generatedOnExecution( incomingObject, session ) ) {
return ( (BeforeExecutionGenerator) subgenerator)
.generate( session, incomingObject, null, INSERT );
if ( !generator.generatedOnExecution( incomingObject, session ) ) {
return generator.generate( session, incomingObject, null, INSERT );
}
else {
throw new IdentifierGenerationException( "Identity generation isn't supported for composite ids" );
Expand All @@ -788,15 +792,15 @@ public Object execute(SharedSessionContractImplementor session, Object incomingO

@Override
public void registerExportables(Database database) {
if ( subgenerator instanceof ExportableProducer ) {
( (ExportableProducer) subgenerator).registerExportables( database );
if ( generator instanceof ExportableProducer exportableProducer ) {
exportableProducer.registerExportables( database );
}
}

@Override
public void initialize(SqlStringGenerationContext context) {
if ( subgenerator instanceof Configurable) {
( (Configurable) subgenerator).initialize( context );
if ( generator instanceof Configurable configurable ) {
configurable.initialize( context );
}
}
}
Expand Down Expand Up @@ -949,7 +953,8 @@ public void setStructColumnNames(String[] structColumnNames) {

public boolean isGeneric() {
if ( isGeneric == null ) {
isGeneric = getComponentClassName() != null && getComponentClass().getTypeParameters().length != 0;
isGeneric = getComponentClassName() != null
&& getComponentClass().getTypeParameters().length > 0;
}
return isGeneric;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.hibernate.sql.exec.spi.JdbcParametersList;
import org.hibernate.sql.results.internal.RowTransformerArrayImpl;

import static org.hibernate.internal.util.NullnessUtil.castNonNull;
import static org.hibernate.sql.results.spi.ListResultsConsumer.UniqueSemantic.FILTER;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ public GeneratedValues coordinateInsert(
SharedSessionContractImplementor session) {
// apply any pre-insert in-memory value generation
final boolean needsDynamicInsert = preInsertInMemoryValueGeneration( values, entity, session );

final EntityMetamodel entityMetamodel = entityPersister().getEntityMetamodel();
final boolean forceIdentifierBinding = entityPersister().getGenerator().generatedOnExecution() && id != null;
if ( entityMetamodel.isDynamicInsert() || needsDynamicInsert || forceIdentifierBinding ) {
final EntityPersister persister = entityPersister();
final boolean forceIdentifierBinding = persister.getGenerator().generatedOnExecution() && id != null;
if ( persister.getEntityMetamodel().isDynamicInsert()
|| needsDynamicInsert || forceIdentifierBinding ) {
return doDynamicInserts( id, values, entity, session, forceIdentifierBinding );
}
else {
Expand Down Expand Up @@ -430,7 +430,7 @@ else if ( isValueGenerationInSql( generator, factory.getJdbcServices().getDialec
if ( tableMapping.isIdentifierTable() && entityPersister().isIdentifierAssignedByInsert() && !forceIdentifierBinding ) {
assert entityPersister().getInsertDelegate() != null;
final OnExecutionGenerator generator = (OnExecutionGenerator) entityPersister().getGenerator();
if ( generator.referenceColumnsInSql( dialect() ) ) {
if ( generator.referenceColumnsInSql( dialect ) ) {
final BasicEntityIdentifierMapping identifierMapping = (BasicEntityIdentifierMapping) entityPersister().getIdentifierMapping();
final String[] columnValues = generator.getReferencedColumnValues( dialect );
tableMapping.getKeyMapping().forEachKeyColumn( (i, column) -> tableInsertBuilder.addKeyColumn(
Expand All @@ -448,8 +448,8 @@ else if ( isValueGenerationInSql( generator, factory.getJdbcServices().getDialec

private static boolean isValueGenerated(Generator generator) {
return generator != null
&& generator.generatesOnInsert()
&& generator.generatedOnExecution();
&& generator.generatesOnInsert()
&& generator.generatedOnExecution();
}

private static boolean isValueGenerationInSql(Generator generator, Dialect dialect) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Locale;
import java.util.function.Supplier;

import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.Internal;
import org.hibernate.StaleObjectStateException;
Expand Down Expand Up @@ -198,7 +197,6 @@ public GeneratedValues update(

final boolean[] attributeUpdateability;
boolean forceDynamicUpdate;

if ( entityPersister().getEntityMetamodel().isDynamicUpdate() && dirtyAttributeIndexes != null ) {
attributeUpdateability = getPropertiesToUpdate( dirtyAttributeIndexes, hasDirtyCollection );
forceDynamicUpdate = true;
Expand Down Expand Up @@ -372,21 +370,15 @@ private static boolean includedInLock(
int position,
SingularAttributeMapping attribute,
EntityPersister persister) {
switch ( persister.optimisticLockStyle() ) {
case NONE:
return false;
case VERSION:
return versionMapping != null
&& versionMapping.getVersionAttribute() == attribute;
return switch ( persister.optimisticLockStyle() ) {
case NONE -> false;
case VERSION -> versionMapping != null
&& versionMapping.getVersionAttribute() == attribute;
// && updateableAttributeIndexes[position];
case ALL:
return attribute.getAttributeMetadata().isIncludedInOptimisticLocking();
case DIRTY:
return attribute.getAttributeMetadata().isIncludedInOptimisticLocking()
&& dirtinessChecker.include( position, attribute );
default:
throw new AssertionFailure( "unknown OptimisticLockStyle" );
}
case ALL -> attribute.getAttributeMetadata().isIncludedInOptimisticLocking();
case DIRTY -> attribute.getAttributeMetadata().isIncludedInOptimisticLocking()
&& dirtinessChecker.include( position, attribute );
};
}

protected Supplier<GeneratedValues> handlePotentialImplicitForcedVersionIncrement(
Expand Down Expand Up @@ -986,7 +978,7 @@ private MutationExecutor updateVersionExecutor(
boolean dynamicUpdate,
boolean batching) {
if ( batching ) {
return updateVersionExecutor(session, group,dynamicUpdate);
return updateVersionExecutor( session, group, dynamicUpdate );
}
return mutationExecutorService.createExecutor( NoBatchKeyAccess.INSTANCE, group, session );

Expand Down Expand Up @@ -1226,9 +1218,7 @@ private void applyAttributeUpdateDetails(
TableUpdateBuilder<?> tableUpdateBuilder,
SharedSessionContractImplementor session) {
final Generator generator = attributeMapping.getGenerator();
if ( isValueGenerated( generator )
&& ( session == null && generator.generatedOnExecution() || generator.generatedOnExecution( entity, session ) )
&& isValueGenerationInSql( generator, dialect ) ) {
if ( needsValueGeneration( entity, session, generator ) ) {
handleValueGeneration( attributeMapping, updateGroupBuilder, (OnExecutionGenerator) generator );
}
else if ( versionMapping != null
Expand All @@ -1245,6 +1235,12 @@ else if ( versionMapping != null
}
}

private boolean needsValueGeneration(Object entity, SharedSessionContractImplementor session, Generator generator) {
return isValueGenerated( generator )
&& (session == null && generator.generatedOnExecution() || generator.generatedOnExecution( entity, session ) )
&& isValueGenerationInSql( generator, dialect );
}

/**
* Contains the aggregated analysis of the update values to determine
* what SQL UPDATE statement(s) should be used to update the entity
Expand Down Expand Up @@ -1606,19 +1602,19 @@ private MutationOperationGroup buildStaticUpdateGroup() {
null,
null,
null,
(index,attribute) -> isValueGenerated( attribute.getGenerator() ) && isValueGenerationInSql( attribute.getGenerator(), dialect() )
(index,attribute) ->
isValueGenerated( attribute.getGenerator() )
&& isValueGenerationInSql( attribute.getGenerator(), dialect() )
|| entityPersister().getPropertyUpdateability()[index],
(index,attribute) -> {
switch ( entityPersister().optimisticLockStyle() ) {
case ALL:
return true;
case VERSION:
final EntityVersionMapping versionMapping = entityPersister().getVersionMapping();
return versionMapping != null && attribute == versionMapping.getVersionAttribute();
default:
return false;
}
},
(index,attribute) ->
switch ( entityPersister().optimisticLockStyle() ) {
case ALL -> true;
case VERSION -> {
final EntityVersionMapping versionMapping = entityPersister().getVersionMapping();
yield versionMapping != null && attribute == versionMapping.getVersionAttribute();
}
default -> false;
},
(index,attribute) -> true,
"", // pass anything here to generate the row id restriction if possible
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@
import org.hibernate.sql.results.graph.FetchParent;
import org.hibernate.sql.results.graph.Fetchable;
import org.hibernate.sql.results.graph.FetchableContainer;
import org.hibernate.sql.results.graph.collection.internal.EagerCollectionFetch;
import org.hibernate.sql.results.graph.entity.EntityResultGraphNode;
import org.hibernate.sql.results.graph.instantiation.internal.DynamicInstantiation;
import org.hibernate.sql.results.graph.internal.ImmutableFetchList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.type;

Expand Down
Loading