4
4
*/
5
5
package org .hibernate .boot .model .internal ;
6
6
7
- import java .util .ArrayList ;
8
7
import java .util .HashMap ;
9
- import java .util .List ;
10
8
import java .util .Map ;
11
- import java .util .Objects ;
12
9
13
10
import org .hibernate .AnnotationException ;
14
11
import org .hibernate .boot .spi .MetadataBuildingContext ;
@@ -71,7 +68,6 @@ public class ComponentPropertyHolder extends AbstractPropertyHolder {
71
68
72
69
private final String embeddedAttributeName ;
73
70
private final Map <String ,AttributeConversionInfo > attributeConversionInfoMap ;
74
- private final List <AnnotatedColumn > annotatedColumns ;
75
71
76
72
public ComponentPropertyHolder (
77
73
Component component ,
@@ -98,12 +94,6 @@ public ComponentPropertyHolder(
98
94
this .embeddedAttributeName = "" ;
99
95
this .attributeConversionInfoMap = processAttributeConversions ( inferredData .getClassOrElementType () );
100
96
}
101
-
102
- if ( parent instanceof ComponentPropertyHolder componentHolder ) {
103
- this .annotatedColumns = componentHolder .annotatedColumns ;
104
- } else {
105
- this .annotatedColumns = new ArrayList <>();
106
- }
107
97
}
108
98
109
99
/**
@@ -229,30 +219,14 @@ public String getEntityName() {
229
219
return component .getComponentClassName ();
230
220
}
231
221
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
-
248
222
@ Override
249
223
public void addProperty (Property property , MemberDetails attributeMemberDetails , AnnotatedColumns columns , ClassDetails declaringClass ) {
250
224
//AnnotatedColumns.checkPropertyConsistency( ); //already called earlier
251
225
// Check table matches between the component and the columns
252
226
// if not, change the component table if no properties are set
253
227
// if a property is set already the core cannot support that
254
228
final Table table = property .getValue ().getTable ();
255
- if ( !table .equals ( getTable () ) ) {
229
+ if ( !table .equals ( getTable () ) || ! columnTableIsExplicit ( table , columns ) ) {
256
230
if ( component .getPropertySpan () == 0 ) {
257
231
component .setTable ( table );
258
232
}
@@ -264,21 +238,19 @@ public void addProperty(Property property, MemberDetails attributeMemberDetails,
264
238
);
265
239
}
266
240
}
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 ) {
270
245
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 ;
277
250
}
278
- this .annotatedColumns .add ( column );
279
251
}
280
252
}
281
- addProperty ( property , attributeMemberDetails , declaringClass ) ;
253
+ return true ;
282
254
}
283
255
284
256
@ Override
0 commit comments