44 */ 
55package  org .hibernate .boot .model .internal ;
66
7- import  java .util .ArrayList ;
87import  java .util .HashMap ;
9- import  java .util .List ;
108import  java .util .Map ;
11- import  java .util .Objects ;
129
1310import  org .hibernate .AnnotationException ;
1411import  org .hibernate .boot .spi .MetadataBuildingContext ;
1512import  org .hibernate .boot .spi .PropertyData ;
16- import  org .hibernate .internal .util .StringHelper ;
1713import  org .hibernate .mapping .AggregateColumn ;
1814import  org .hibernate .mapping .Component ;
1915import  org .hibernate .mapping .Join ;
@@ -72,7 +68,6 @@ public class ComponentPropertyHolder extends AbstractPropertyHolder {
7268
7369	private  final  String  embeddedAttributeName ;
7470	private  final  Map <String ,AttributeConversionInfo > attributeConversionInfoMap ;
75- 	private  final  List <AnnotatedColumn > annotatedColumns ;
7671
7772	public  ComponentPropertyHolder (
7873			Component  component ,
@@ -99,12 +94,6 @@ public ComponentPropertyHolder(
9994			this .embeddedAttributeName  = "" ;
10095			this .attributeConversionInfoMap  = processAttributeConversions ( inferredData .getClassOrElementType () );
10196		}
102- 
103- 		if  ( parent  instanceof  ComponentPropertyHolder  parentHolder  ) {
104- 			this .annotatedColumns  = parentHolder .annotatedColumns ;
105- 		} else  {
106- 			this .annotatedColumns  = new  ArrayList <>();
107- 		}
10897	}
10998
11099	/** 
@@ -236,7 +225,12 @@ public void addProperty(Property property, MemberDetails attributeMemberDetails,
236225		// Check table matches between the component and the columns 
237226		// if not, change the component table if no properties are set 
238227		// if a property is set already the core cannot support that 
239- 		final  Table  table  = property .getValue ().getTable ();
228+ 		assert  property .getValue ().getTable () == columns .getTable ();
229+ 		setTable ( property .getValue ().getTable () );
230+ 		addProperty ( property , attributeMemberDetails , declaringClass  );
231+ 	}
232+ 
233+ 	void  setTable (Table  table ) {
240234		if  ( !table .equals ( getTable () ) ) {
241235			if  ( component .getPropertySpan () == 0  ) {
242236				component .setTable ( table  );
@@ -248,27 +242,8 @@ public void addProperty(Property property, MemberDetails attributeMemberDetails,
248242						+ " (all properties of the embeddable class must map to the same table)" 
249243				);
250244			}
251- 		}
252- 		if  ( columns  != null  ) {
253- 			annotatedColumns .addAll ( columns .getColumns () );
254- 		}
255- 		addProperty ( property , attributeMemberDetails , declaringClass  );
256- 	}
257- 
258- 	public  void  checkPropertyConsistency () {
259- 		if  ( annotatedColumns .size () > 1  ) {
260- 			for  ( int  currentIndex  = 1 ; currentIndex  < annotatedColumns .size (); currentIndex ++ ) {
261- 				final  AnnotatedColumn  current  = annotatedColumns .get ( currentIndex  );
262- 				final  AnnotatedColumn  previous  = annotatedColumns .get ( currentIndex  - 1  );
263- 				if  ( !Objects .equals (
264- 						StringHelper .nullIfEmpty ( current .getExplicitTableName () ),
265- 						StringHelper .nullIfEmpty ( previous .getExplicitTableName () ) ) ) {
266- 					throw  new  AnnotationException (
267- 							"Embeddable class '"  + component .getComponentClassName ()
268- 							+ "' has properties mapped to two different tables" 
269- 							+ " (all properties of the embeddable class must map to the same table)" 
270- 					);
271- 				}
245+ 			if  ( parent  instanceof  ComponentPropertyHolder  parentComponentHolder  ) {
246+ 				parentComponentHolder .setTable ( table  );
272247			}
273248		}
274249	}
0 commit comments