@@ -162,6 +162,7 @@ else if ( action.performOnLazyProperty() && type instanceof EntityType ) {
162162 action ,
163163 cascadePoint ,
164164 eventSource ,
165+ persister .getEntityName (),
165166 null ,
166167 parent ,
167168 child ,
@@ -203,6 +204,7 @@ private static <T> void cascadeProperty(
203204 final CascadingAction <T > action ,
204205 final CascadePoint cascadePoint ,
205206 final EventSource eventSource ,
207+ final String entityName ,
206208 List <String > componentPath ,
207209 final Object parent ,
208210 final Object child ,
@@ -219,6 +221,8 @@ private static <T> void cascadeProperty(
219221 action ,
220222 cascadePoint ,
221223 eventSource ,
224+ entityName ,
225+ propertyName ,
222226 componentPath ,
223227 parent ,
224228 child ,
@@ -240,6 +244,7 @@ else if ( type instanceof ComponentType componentType ) {
240244 action ,
241245 cascadePoint ,
242246 eventSource ,
247+ entityName ,
243248 componentPath ,
244249 parent ,
245250 child ,
@@ -385,6 +390,7 @@ private static <T> void cascadeComponent(
385390 final CascadingAction <T > action ,
386391 final CascadePoint cascadePoint ,
387392 final EventSource eventSource ,
393+ final String entityName ,
388394 final List <String > componentPath ,
389395 final Object parent ,
390396 final Object child ,
@@ -398,7 +404,7 @@ private static <T> void cascadeComponent(
398404 final String subPropertyName = propertyNames [i ];
399405 final Type subPropertyType = types [i ];
400406 if ( action .appliesTo ( subPropertyType , componentPropertyStyle )
401- || componentPropertyStyle .hasOrphanDelete () && action .deleteOrphans () ) {
407+ || componentPropertyStyle .hasOrphanDelete () && action .deleteOrphans () ) {
402408 if ( children == null ) {
403409 // Get children on demand.
404410 children = componentType .getPropertyValues ( child , eventSource );
@@ -407,6 +413,7 @@ private static <T> void cascadeComponent(
407413 action ,
408414 cascadePoint ,
409415 eventSource ,
416+ entityName ,
410417 componentPath ,
411418 parent ,
412419 children [i ],
@@ -424,6 +431,8 @@ private static <T> void cascadeAssociation(
424431 final CascadingAction <T > action ,
425432 final CascadePoint cascadePoint ,
426433 final EventSource eventSource ,
434+ final String entityName ,
435+ final String propertyName ,
427436 final List <String > componentPath ,
428437 final Object parent ,
429438 final Object child ,
@@ -432,13 +441,27 @@ private static <T> void cascadeAssociation(
432441 final T anything ,
433442 final boolean isCascadeDeleteEnabled ) {
434443 if ( type instanceof EntityType || type instanceof AnyType ) {
435- cascadeToOne ( action , eventSource , parent , child , type , style , anything , isCascadeDeleteEnabled );
444+ cascadeToOne (
445+ action ,
446+ eventSource ,
447+ parent ,
448+ child ,
449+ type ,
450+ style ,
451+ anything ,
452+ isCascadeDeleteEnabled ,
453+ entityName ,
454+ propertyName ,
455+ componentPath
456+ );
436457 }
437458 else if ( type instanceof CollectionType collectionType ) {
438459 cascadeCollection (
439460 action ,
440461 cascadePoint ,
441462 eventSource ,
463+ entityName ,
464+ propertyName ,
442465 componentPath ,
443466 parent ,
444467 child ,
@@ -456,6 +479,8 @@ private static <T> void cascadeCollection(
456479 final CascadingAction <T > action ,
457480 final CascadePoint cascadePoint ,
458481 final EventSource eventSource ,
482+ final String entityName ,
483+ final String propertyName ,
459484 final List <String > componentPath ,
460485 final Object parent ,
461486 final Object child ,
@@ -474,6 +499,8 @@ private static <T> void cascadeCollection(
474499 ? CascadePoint .AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION
475500 : cascadePoint ,
476501 eventSource ,
502+ entityName ,
503+ propertyName ,
477504 componentPath ,
478505 parent ,
479506 child ,
@@ -497,17 +524,27 @@ private static <T> void cascadeToOne(
497524 final Type type ,
498525 final CascadeStyle style ,
499526 final T anything ,
500- final boolean isCascadeDeleteEnabled ) {
501- final String entityName =
502- type instanceof EntityType entityType
503- ? entityType .getAssociatedEntityName ()
504- : null ;
527+ final boolean isCascadeDeleteEnabled ,
528+ final String parentEntityName ,
529+ final String propertyName ,
530+ final List <String > componentPath ) {
505531 if ( style .reallyDoCascade ( action ) ) {
506532 //not really necessary, but good for consistency...
507533 final PersistenceContext persistenceContext = eventSource .getPersistenceContextInternal ();
508534 persistenceContext .addChildParent ( child , parent );
509535 try {
510- action .cascade ( eventSource , child , entityName , anything , isCascadeDeleteEnabled );
536+ action .cascade (
537+ eventSource ,
538+ child ,
539+ type instanceof EntityType entityType
540+ ? entityType .getAssociatedEntityName ()
541+ : null ,
542+ parentEntityName ,
543+ propertyName ,
544+ componentPath ,
545+ anything ,
546+ isCascadeDeleteEnabled
547+ );
511548 }
512549 finally {
513550 persistenceContext .removeChildParent ( child );
@@ -522,6 +559,8 @@ private static <T> void cascadeCollectionElements(
522559 final CascadingAction <T > action ,
523560 final CascadePoint cascadePoint ,
524561 final EventSource eventSource ,
562+ final String entityName ,
563+ final String propertyName ,
525564 final List <String > componentPath ,
526565 final Object parent ,
527566 final Object child ,
@@ -546,12 +585,14 @@ private static <T> void cascadeCollectionElements(
546585 action ,
547586 cascadePoint ,
548587 eventSource ,
588+ entityName ,
549589 componentPath ,
550590 parent ,
551591 iterator .next (),
552592 elemType ,
553593 style ,
554- collectionType .getRole ().substring ( collectionType .getRole ().lastIndexOf ('.' ) + 1 ),
594+ propertyName ,
595+ // collectionType.getRole().substring( collectionType.getRole().lastIndexOf('.') + 1 ),
555596 anything ,
556597 isCascadeDeleteEnabled
557598 );
@@ -583,8 +624,8 @@ private static <T> void cascadeCollectionElements(
583624 // we can do the cast since orphan-delete does not apply to:
584625 // 1. newly instantiated collections
585626 // 2. arrays (we can't track orphans for detached arrays)
586- final String entityName = collectionType .getAssociatedEntityName ( eventSource .getFactory () );
587- deleteOrphans ( eventSource , entityName , persistentCollection );
627+ final String elementEntityName = collectionType .getAssociatedEntityName ( eventSource .getFactory () );
628+ deleteOrphans ( eventSource , elementEntityName , persistentCollection );
588629
589630 if ( traceEnabled ) {
590631 LOG .tracev ( "Done deleting orphans for collection: {0}" , collectionType .getRole () );
0 commit comments