44 */ 
55package  org .hibernate .boot .model .internal ;
66
7+ import  java .util .ArrayList ;
78import  java .util .HashMap ;
9+ import  java .util .List ;
810import  java .util .Map ;
911import  java .util .Objects ;
10- import  java .util .concurrent .atomic .AtomicReference ;
1112
1213import  org .hibernate .AnnotationException ;
1314import  org .hibernate .boot .spi .MetadataBuildingContext ;
1415import  org .hibernate .boot .spi .PropertyData ;
16+ import  org .hibernate .internal .util .StringHelper ;
1517import  org .hibernate .mapping .AggregateColumn ;
1618import  org .hibernate .mapping .Component ;
1719import  org .hibernate .mapping .Join ;
3133import  static  org .hibernate .boot .model .internal .ClassPropertyHolder .handleGenericComponentProperty ;
3234import  static  org .hibernate .boot .model .internal .PropertyBinder .hasIdAnnotation ;
3335import  static  org .hibernate .internal .util .StringHelper .isEmpty ;
34- import  static  org .hibernate .internal .util .StringHelper .nullIfEmpty ;
3536import  static  org .hibernate .internal .util .StringHelper .qualifyConditionally ;
3637import  static  org .hibernate .spi .NavigablePath .IDENTIFIER_MAPPER_PROPERTY ;
3738
@@ -71,7 +72,7 @@ public class ComponentPropertyHolder extends AbstractPropertyHolder {
7172
7273	private  final  String  embeddedAttributeName ;
7374	private  final  Map <String ,AttributeConversionInfo > attributeConversionInfoMap ;
74- 	private  final  AtomicReference <AnnotatedColumn > annotatedColumn ;
75+ 	private  final  List <AnnotatedColumn > annotatedColumns ;
7576
7677	public  ComponentPropertyHolder (
7778			Component  component ,
@@ -100,9 +101,9 @@ public ComponentPropertyHolder(
100101		}
101102
102103		if  ( parent  instanceof  ComponentPropertyHolder  parentHolder  ) {
103- 			this .annotatedColumn  = parentHolder .annotatedColumn ;
104+ 			this .annotatedColumns  = parentHolder .annotatedColumns ;
104105		} else  {
105- 			this .annotatedColumn  = new  AtomicReference <>();
106+ 			this .annotatedColumns  = new  ArrayList <>();
106107		}
107108	}
108109
@@ -236,7 +237,7 @@ public void addProperty(Property property, MemberDetails attributeMemberDetails,
236237		// if not, change the component table if no properties are set 
237238		// if a property is set already the core cannot support that 
238239		final  Table  table  = property .getValue ().getTable ();
239- 		if  ( !table .equals ( getTable () ) || ! columnTableIsConsistent (  columns  )  ) {
240+ 		if  ( !table .equals ( getTable () ) ) {
240241			if  ( component .getPropertySpan () == 0  ) {
241242				component .setTable ( table  );
242243			}
@@ -248,21 +249,28 @@ public void addProperty(Property property, MemberDetails attributeMemberDetails,
248249				);
249250			}
250251		}
252+ 		if  ( columns  != null  ) {
253+ 			annotatedColumns .addAll ( columns .getColumns () );
254+ 		}
251255		addProperty ( property , attributeMemberDetails , declaringClass  );
252256	}
253257
254- 	private  boolean  columnTableIsConsistent (AnnotatedColumns  columns ) {
255- 		if  ( columns  != null  ) {
256- 			for  ( AnnotatedColumn  current  : columns .getColumns () ) {
257- 				final  AnnotatedColumn  previous  = annotatedColumn .getAndSet ( current  );
258- 				if  ( previous  != null  && !Objects .equals (
259- 							nullIfEmpty ( current .getExplicitTableName () ),
260- 							nullIfEmpty ( previous .getExplicitTableName () ) ) ) {
261- 					return  false ;
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+ 					);
262271				}
263272			}
264273		}
265- 		return  true ;
266274	}
267275
268276	@ Override 
0 commit comments