6
6
*/
7
7
package org .hibernate .boot .model .internal ;
8
8
9
- import java .util .ArrayList ;
10
9
import java .util .HashMap ;
11
- import java .util .List ;
12
10
import java .util .Map ;
13
- import java .util .Objects ;
14
11
15
12
import org .hibernate .AnnotationException ;
16
13
import org .hibernate .annotations .common .reflection .XClass ;
17
14
import org .hibernate .annotations .common .reflection .XProperty ;
18
15
import org .hibernate .boot .spi .MetadataBuildingContext ;
19
16
import org .hibernate .boot .spi .PropertyData ;
20
- import org .hibernate .internal .util .StringHelper ;
21
17
import org .hibernate .mapping .AggregateColumn ;
22
18
import org .hibernate .mapping .Component ;
23
19
import org .hibernate .mapping .Join ;
@@ -78,7 +74,6 @@ public class ComponentPropertyHolder extends AbstractPropertyHolder {
78
74
79
75
private final String embeddedAttributeName ;
80
76
private final Map <String ,AttributeConversionInfo > attributeConversionInfoMap ;
81
- private final List <AnnotatedColumn > annotatedColumns ;
82
77
83
78
public ComponentPropertyHolder (
84
79
Component component ,
@@ -105,12 +100,6 @@ public ComponentPropertyHolder(
105
100
this .embeddedAttributeName = "" ;
106
101
this .attributeConversionInfoMap = processAttributeConversions ( inferredData .getClassOrPluralElement () );
107
102
}
108
-
109
- if ( parent instanceof ComponentPropertyHolder ) {
110
- this .annotatedColumns = ( (ComponentPropertyHolder ) parent ).annotatedColumns ;
111
- } else {
112
- this .annotatedColumns = new ArrayList <>();
113
- }
114
103
}
115
104
116
105
/**
@@ -281,7 +270,12 @@ public void addProperty(Property property, AnnotatedColumns columns, XClass decl
281
270
// Check table matches between the component and the columns
282
271
// if not, change the component table if no properties are set
283
272
// 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 ) {
285
279
if ( !table .equals ( getTable () ) ) {
286
280
if ( component .getPropertySpan () == 0 ) {
287
281
component .setTable ( table );
@@ -293,27 +287,8 @@ public void addProperty(Property property, AnnotatedColumns columns, XClass decl
293
287
+ " (all properties of the embeddable class must map to the same table)"
294
288
);
295
289
}
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 );
317
292
}
318
293
}
319
294
}
0 commit comments