Skip to content

Commit 087d51d

Browse files
committed
HHH-10291 - Fix Partially generated composite attribute is not retrieved after insert
1 parent d3b4ae7 commit 087d51d

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
import org.hibernate.tuple.entity.EntityTuplizer;
122122
import org.hibernate.type.AssociationType;
123123
import org.hibernate.type.CollectionType;
124+
import org.hibernate.type.ComponentType;
124125
import org.hibernate.type.CompositeType;
125126
import org.hibernate.type.EntityType;
126127
import org.hibernate.type.Type;
@@ -4731,8 +4732,7 @@ private void processGeneratedProperties(
47314732
int propertyIndex = -1;
47324733
for ( NonIdentifierAttribute attribute : entityMetamodel.getProperties() ) {
47334734
propertyIndex++;
4734-
final ValueGeneration valueGeneration = attribute.getValueGenerationStrategy();
4735-
if ( isReadRequired( valueGeneration, matchTiming ) ) {
4735+
if ( isValueGenerationRequired( attribute, matchTiming ) ) {
47364736
final Object hydratedState = attribute.getType().hydrate(
47374737
rs, getPropertyAliases(
47384738
"",
@@ -4743,6 +4743,7 @@ rs, getPropertyAliases(
47434743
setPropertyValue( entity, propertyIndex, state[propertyIndex] );
47444744
}
47454745
}
4746+
47464747
// for ( int i = 0; i < getPropertySpan(); i++ ) {
47474748
// if ( includeds[i] != ValueInclusion.NONE ) {
47484749
// Object hydratedState = getPropertyTypes()[i].hydrate( rs, getPropertyAliases( "", i ), session, entity );
@@ -4772,6 +4773,22 @@ rs, getPropertyAliases(
47724773

47734774
}
47744775

4776+
private boolean isValueGenerationRequired(NonIdentifierAttribute attribute, GenerationTiming matchTiming) {
4777+
if ( attribute.getType() instanceof ComponentType ) {
4778+
final ComponentType type = (ComponentType) attribute.getType();
4779+
final ValueGeneration[] propertyValueGenerationStrategies = type.getPropertyValueGenerationStrategies();
4780+
for ( int i = 0; i < propertyValueGenerationStrategies.length; i++ ) {
4781+
if ( isReadRequired( propertyValueGenerationStrategies[i], matchTiming ) ) {
4782+
return true;
4783+
}
4784+
}
4785+
return false;
4786+
}
4787+
else {
4788+
return isReadRequired( attribute.getValueGenerationStrategy(), matchTiming );
4789+
}
4790+
}
4791+
47754792
/**
47764793
* Whether the given value generation strategy requires to read the value from the database or not.
47774794
*/

hibernate-core/src/main/java/org/hibernate/tuple/ValueGeneration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
*/
77
package org.hibernate.tuple;
88

9+
import java.io.Serializable;
10+
911
/**
1012
* Describes the generation of property values.
1113
*
1214
* @author Steve Ebersole
1315
*/
14-
public interface ValueGeneration {
16+
public interface ValueGeneration extends Serializable {
1517
/**
1618
* When is this value generated : NEVER, INSERT, ALWAYS (INSERT+UPDATE)
1719
*

hibernate-core/src/main/java/org/hibernate/type/ComponentType.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.hibernate.internal.util.StringHelper;
2929
import org.hibernate.internal.util.collections.ArrayHelper;
3030
import org.hibernate.tuple.StandardProperty;
31+
import org.hibernate.tuple.ValueGeneration;
3132
import org.hibernate.tuple.component.ComponentMetamodel;
3233
import org.hibernate.tuple.component.ComponentTuplizer;
3334

@@ -41,6 +42,7 @@ public class ComponentType extends AbstractType implements CompositeType, Proced
4142
private final TypeFactory.TypeScope typeScope;
4243
private final String[] propertyNames;
4344
private final Type[] propertyTypes;
45+
private final ValueGeneration[] propertyValueGenerationStrategies;
4446
private final boolean[] propertyNullability;
4547
protected final int propertySpan;
4648
private final CascadeStyle[] cascade;
@@ -58,6 +60,7 @@ public ComponentType(TypeFactory.TypeScope typeScope, ComponentMetamodel metamod
5860
this.propertySpan = metamodel.getPropertySpan();
5961
this.propertyNames = new String[propertySpan];
6062
this.propertyTypes = new Type[propertySpan];
63+
this.propertyValueGenerationStrategies = new ValueGeneration[propertySpan];
6164
this.propertyNullability = new boolean[propertySpan];
6265
this.cascade = new CascadeStyle[propertySpan];
6366
this.joinedFetch = new FetchMode[propertySpan];
@@ -72,6 +75,7 @@ public ComponentType(TypeFactory.TypeScope typeScope, ComponentMetamodel metamod
7275
if ( !prop.isNullable() ) {
7376
hasNotNullProperty = true;
7477
}
78+
this.propertyValueGenerationStrategies[i] = prop.getValueGenerationStrategy();
7579
}
7680

7781
this.entityMode = metamodel.getEntityMode();
@@ -448,6 +452,10 @@ public Type[] getSubtypes() {
448452
return propertyTypes;
449453
}
450454

455+
public ValueGeneration[] getPropertyValueGenerationStrategies() {
456+
return propertyValueGenerationStrategies;
457+
}
458+
451459
@Override
452460
public String getName() {
453461
return "component" + ArrayHelper.toString( propertyNames );

0 commit comments

Comments
 (0)