Skip to content

Commit 913e50b

Browse files
committed
HHH-19542: Consolidate the idea
1 parent 6631e16 commit 913e50b

File tree

2 files changed

+11
-41
lines changed

2 files changed

+11
-41
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/internal/ComponentPropertyHolder.java

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44
*/
55
package org.hibernate.boot.model.internal;
66

7-
import java.util.ArrayList;
87
import java.util.HashMap;
9-
import java.util.List;
108
import java.util.Map;
11-
import java.util.Objects;
129

1310
import org.hibernate.AnnotationException;
1411
import org.hibernate.boot.spi.MetadataBuildingContext;
@@ -71,7 +68,6 @@ public class ComponentPropertyHolder extends AbstractPropertyHolder {
7168

7269
private final String embeddedAttributeName;
7370
private final Map<String,AttributeConversionInfo> attributeConversionInfoMap;
74-
private final List<AnnotatedColumn> annotatedColumns;
7571

7672
public ComponentPropertyHolder(
7773
Component component,
@@ -98,12 +94,6 @@ public ComponentPropertyHolder(
9894
this.embeddedAttributeName = "";
9995
this.attributeConversionInfoMap = processAttributeConversions( inferredData.getClassOrElementType() );
10096
}
101-
102-
if ( parent instanceof ComponentPropertyHolder componentHolder ) {
103-
this.annotatedColumns = componentHolder.annotatedColumns;
104-
} else {
105-
this.annotatedColumns = new ArrayList<>();
106-
}
10797
}
10898

10999
/**
@@ -229,30 +219,14 @@ public String getEntityName() {
229219
return component.getComponentClassName();
230220
}
231221

232-
public void checkPropertyConsistency() {
233-
if ( annotatedColumns.size() > 1 ) {
234-
for ( int currentIndex = 1; currentIndex < annotatedColumns.size(); currentIndex++ ) {
235-
final AnnotatedColumn current = annotatedColumns.get( currentIndex );
236-
final AnnotatedColumn previous = annotatedColumns.get( currentIndex - 1 );
237-
if ( !Objects.equals( current.getExplicitTableName(), previous.getExplicitTableName() ) ) {
238-
throw new AnnotationException(
239-
"Embeddable class '" + component.getComponentClassName()
240-
+ "' has properties mapped to two different tables"
241-
+ " (all properties of the embeddable class must map to the same table)"
242-
);
243-
}
244-
}
245-
}
246-
}
247-
248222
@Override
249223
public void addProperty(Property property, MemberDetails attributeMemberDetails, AnnotatedColumns columns, ClassDetails declaringClass) {
250224
//AnnotatedColumns.checkPropertyConsistency( ); //already called earlier
251225
// Check table matches between the component and the columns
252226
// if not, change the component table if no properties are set
253227
// if a property is set already the core cannot support that
254228
final Table table = property.getValue().getTable();
255-
if ( !table.equals( getTable() ) ) {
229+
if ( !table.equals( getTable() ) || !columnTableIsExplicit( table, columns ) ) {
256230
if ( component.getPropertySpan() == 0 ) {
257231
component.setTable( table );
258232
}
@@ -264,21 +238,19 @@ public void addProperty(Property property, MemberDetails attributeMemberDetails,
264238
);
265239
}
266240
}
267-
// In the case of a nested component, AnnotatedColumns.checkPropertyConsistency()
268-
// is not called since we rely on the underlying value, we build a synthetic annotated
269-
// columns to check the consistency after all properties are set.
241+
addProperty( property, attributeMemberDetails, declaringClass );
242+
}
243+
244+
private boolean columnTableIsExplicit(Table table, AnnotatedColumns columns) {
270245
if ( columns != null ) {
271-
for ( AnnotatedColumn column : columns.getColumns() ) {
272-
// The following has to be added otherwise every single
273-
// property must be annotated with @Column
274-
// Can be removed in version where the binder is stricter
275-
if ( column.getExplicitTableName() == null ) {
276-
column.setExplicitTableName( "" );
246+
for ( AnnotatedColumn current : columns.getColumns() ) {
247+
final String explicitTableName = current.getExplicitTableName();
248+
if ( columns.isSecondary() && !table.getName().equals( explicitTableName ) ) {
249+
return false;
277250
}
278-
this.annotatedColumns.add( column );
279251
}
280252
}
281-
addProperty( property, attributeMemberDetails, declaringClass );
253+
return true;
282254
}
283255

284256
@Override

hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,6 @@ else if ( member.hasDirectAnnotationUsage( GeneratedValue.class ) ) {
579579
}
580580
}
581581

582-
subholder.checkPropertyConsistency();
583-
584582
if ( compositeUserType != null ) {
585583
processCompositeUserType( component, compositeUserType );
586584
}
@@ -983,7 +981,7 @@ static Component createEmbeddable(
983981
MetadataBuildingContext context) {
984982
final Component component = new Component( context, propertyHolder.getPersistentClass() );
985983
component.setEmbedded( isComponentEmbedded );
986-
// yuk
984+
//yuk
987985
component.setTable( propertyHolder.getTable() );
988986
if ( isIdentifierMapper
989987
|| isComponentEmbedded && inferredData.getPropertyName() == null ) {

0 commit comments

Comments
 (0)