66 */
77package org .hibernate .boot .model .internal ;
88
9- import java .util .ArrayList ;
109import java .util .HashMap ;
11- import java .util .List ;
1210import java .util .Map ;
13- import java .util .Objects ;
1411
1512import org .hibernate .AnnotationException ;
1613import org .hibernate .annotations .common .reflection .XClass ;
1714import org .hibernate .annotations .common .reflection .XProperty ;
1815import org .hibernate .boot .spi .MetadataBuildingContext ;
1916import org .hibernate .boot .spi .PropertyData ;
20- import org .hibernate .internal .util .StringHelper ;
2117import org .hibernate .mapping .AggregateColumn ;
2218import org .hibernate .mapping .Component ;
2319import org .hibernate .mapping .Join ;
@@ -78,7 +74,6 @@ public class ComponentPropertyHolder extends AbstractPropertyHolder {
7874
7975 private final String embeddedAttributeName ;
8076 private final Map <String ,AttributeConversionInfo > attributeConversionInfoMap ;
81- private final List <AnnotatedColumn > annotatedColumns ;
8277
8378 public ComponentPropertyHolder (
8479 Component component ,
@@ -105,12 +100,6 @@ public ComponentPropertyHolder(
105100 this .embeddedAttributeName = "" ;
106101 this .attributeConversionInfoMap = processAttributeConversions ( inferredData .getClassOrPluralElement () );
107102 }
108-
109- if ( parent instanceof ComponentPropertyHolder ) {
110- this .annotatedColumns = ( (ComponentPropertyHolder ) parent ).annotatedColumns ;
111- } else {
112- this .annotatedColumns = new ArrayList <>();
113- }
114103 }
115104
116105 /**
@@ -281,7 +270,12 @@ public void addProperty(Property property, AnnotatedColumns columns, XClass decl
281270 // Check table matches between the component and the columns
282271 // if not, change the component table if no properties are set
283272 // if a property is set already the core cannot support that
284- final Table table = property .getValue ().getTable ();
273+ assert columns == null || property .getValue ().getTable () == columns .getTable ();
274+ setTable ( property .getValue ().getTable () );
275+ addProperty ( property , declaringClass );
276+ }
277+
278+ private void setTable (Table table ) {
285279 if ( !table .equals ( getTable () ) ) {
286280 if ( component .getPropertySpan () == 0 ) {
287281 component .setTable ( table );
@@ -293,27 +287,8 @@ public void addProperty(Property property, AnnotatedColumns columns, XClass decl
293287 + " (all properties of the embeddable class must map to the same table)"
294288 );
295289 }
296- }
297- if ( columns != null ) {
298- annotatedColumns .addAll ( columns .getColumns () );
299- }
300- addProperty ( property , declaringClass );
301- }
302-
303- public void checkPropertyConsistency () {
304- if ( annotatedColumns .size () > 1 ) {
305- for ( int currentIndex = 1 ; currentIndex < annotatedColumns .size (); currentIndex ++ ) {
306- final AnnotatedColumn current = annotatedColumns .get ( currentIndex );
307- final AnnotatedColumn previous = annotatedColumns .get ( currentIndex - 1 );
308- if ( !Objects .equals (
309- StringHelper .nullIfEmpty ( current .getExplicitTableName () ),
310- StringHelper .nullIfEmpty ( previous .getExplicitTableName () ) ) ) {
311- throw new AnnotationException (
312- "Embeddable class '" + component .getComponentClassName ()
313- + "' has properties mapped to two different tables"
314- + " (all properties of the embeddable class must map to the same table)"
315- );
316- }
290+ if ( parent instanceof ComponentPropertyHolder ) {
291+ ( (ComponentPropertyHolder ) parent ).setTable ( table );
317292 }
318293 }
319294 }
0 commit comments