@@ -988,7 +988,9 @@ static Component createEmbeddable(
988988 component .setComponentClassName ( component .getOwner ().getClassName () );
989989 }
990990 else {
991- component .setComponentClassName ( inferredData .getClassOrElementType ().getName () );
991+ final TypeDetails type = inferredData .getClassOrElementType ();
992+ component .setComponentClassName ( type .getName () );
993+ checkEmbeddableRecursiveHierarchy ( type , inferredData , propertyHolder );
992994 }
993995 component .setCustomInstantiator ( customInstantiatorImpl );
994996 final Constructor <?> constructor = resolveInstantiator ( inferredData .getClassOrElementType () );
@@ -1003,6 +1005,30 @@ static Component createEmbeddable(
10031005 return component ;
10041006 }
10051007
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+
10061032 private static void applyColumnNamingPattern (Component component , PropertyData inferredData ) {
10071033 final Class <?> componentClass = component .getComponentClass ();
10081034 if ( componentClass == null || Map .class .equals ( componentClass ) ) {
0 commit comments