@@ -988,7 +988,9 @@ static Component createEmbeddable(
988
988
component .setComponentClassName ( component .getOwner ().getClassName () );
989
989
}
990
990
else {
991
- component .setComponentClassName ( inferredData .getClassOrElementType ().getName () );
991
+ final TypeDetails type = inferredData .getClassOrElementType ();
992
+ component .setComponentClassName ( type .getName () );
993
+ checkEmbeddableRecursiveHierarchy ( type , inferredData , propertyHolder );
992
994
}
993
995
component .setCustomInstantiator ( customInstantiatorImpl );
994
996
final Constructor <?> constructor = resolveInstantiator ( inferredData .getClassOrElementType () );
@@ -1003,6 +1005,30 @@ static Component createEmbeddable(
1003
1005
return component ;
1004
1006
}
1005
1007
1008
+ private static void checkEmbeddableRecursiveHierarchy (
1009
+ TypeDetails type ,
1010
+ PropertyData propertyData ,
1011
+ PropertyHolder propertyHolder ) {
1012
+ final ClassDetails embeddableClass = type .determineRawClass ();
1013
+ while ( propertyHolder .isComponent () ) {
1014
+ final ComponentPropertyHolder componentHolder = (ComponentPropertyHolder ) propertyHolder ;
1015
+ // we need to check that the embeddable is not used in a recursive hierarchy
1016
+ ClassDetails classDetails = embeddableClass ;
1017
+ while ( classDetails != null ) {
1018
+ if ( propertyHolder .getClassName ().equals ( classDetails .getClassName () ) ) {
1019
+ throw new MappingException ( String .format (
1020
+ Locale .ROOT ,
1021
+ "Recursive embeddable mapping detected for property '%s' for type [%s]" ,
1022
+ getPath ( propertyHolder , propertyData ),
1023
+ propertyHolder .getClassName ()
1024
+ ) );
1025
+ }
1026
+ classDetails = classDetails .getSuperClass ();
1027
+ }
1028
+ propertyHolder = componentHolder .parent ;
1029
+ }
1030
+ }
1031
+
1006
1032
private static void applyColumnNamingPattern (Component component , PropertyData inferredData ) {
1007
1033
final Class <?> componentClass = component .getComponentClass ();
1008
1034
if ( componentClass == null || Map .class .equals ( componentClass ) ) {
0 commit comments