@@ -275,25 +275,29 @@ else if ( generator.generatedOnExecution( entity, this ) ) {
275275 }
276276
277277 private void recreateCollections (Object entity , Object id , EntityPersister persister ) {
278- forEachOwnedCollection ( entity , id , persister ,
279- (descriptor , collection ) -> {
280- firePreRecreate ( collection , descriptor );
281- final EventMonitor eventMonitor = getEventMonitor ();
282- final DiagnosticEvent event = eventMonitor .beginCollectionRecreateEvent ();
283- boolean success = false ;
284- try {
285- descriptor .recreate ( collection , id , this );
286- success = true ;
287- }
288- finally {
289- eventMonitor .completeCollectionRecreateEvent ( event , id , descriptor .getRole (), success , this );
290- }
291- final StatisticsImplementor statistics = getFactory ().getStatistics ();
292- if ( statistics .isStatisticsEnabled () ) {
293- statistics .recreateCollection ( descriptor .getRole () );
294- }
295- firePostRecreate ( collection , descriptor );
296- } );
278+ if ( persister .hasOwnedCollections () ) {
279+ final String entityName = persister .getEntityName ();
280+ final EventMonitor eventMonitor = getEventMonitor ();
281+ final StatisticsImplementor statistics = getFactory ().getStatistics ();
282+ forEachOwnedCollection ( entity , id , persister ,
283+ (descriptor , collection ) -> {
284+ final String role = descriptor .getRole ();
285+ firePreRecreate ( collection , id , entityName , entity );
286+ final DiagnosticEvent event = eventMonitor .beginCollectionRecreateEvent ();
287+ boolean success = false ;
288+ try {
289+ descriptor .recreate ( collection , id , this );
290+ success = true ;
291+ }
292+ finally {
293+ eventMonitor .completeCollectionRecreateEvent ( event , id , role , success , this );
294+ }
295+ if ( statistics .isStatisticsEnabled () ) {
296+ statistics .recreateCollection ( role );
297+ }
298+ firePostRecreate ( collection , id , entityName , entity );
299+ } );
300+ }
297301 }
298302
299303 // deletes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -347,25 +351,29 @@ public void delete(String entityName, Object entity) {
347351 }
348352
349353 private void removeCollections (Object entity , Object id , EntityPersister persister ) {
350- forEachOwnedCollection ( entity , id , persister ,
351- (descriptor , collection ) -> {
352- firePreRemove ( collection , entity , descriptor );
353- final EventMonitor eventMonitor = getEventMonitor ();
354- final DiagnosticEvent event = eventMonitor .beginCollectionRemoveEvent ();
355- boolean success = false ;
356- try {
357- descriptor .remove ( id , this );
358- success = true ;
359- }
360- finally {
361- eventMonitor .completeCollectionRemoveEvent ( event , id , descriptor .getRole (), success , this );
362- }
363- firePostRemove ( collection , entity , descriptor );
364- final StatisticsImplementor statistics = getFactory ().getStatistics ();
365- if ( statistics .isStatisticsEnabled () ) {
366- statistics .removeCollection ( descriptor .getRole () );
367- }
368- } );
354+ if ( persister .hasOwnedCollections () ) {
355+ final String entityName = persister .getEntityName ();
356+ final EventMonitor eventMonitor = getEventMonitor ();
357+ final StatisticsImplementor statistics = getFactory ().getStatistics ();
358+ forEachOwnedCollection ( entity , id , persister ,
359+ (descriptor , collection ) -> {
360+ final String role = descriptor .getRole ();
361+ firePreRemove ( collection , id , entityName , entity );
362+ final DiagnosticEvent event = eventMonitor .beginCollectionRemoveEvent ();
363+ boolean success = false ;
364+ try {
365+ descriptor .remove ( id , this );
366+ success = true ;
367+ }
368+ finally {
369+ eventMonitor .completeCollectionRemoveEvent ( event , id , role , success , this );
370+ }
371+ firePostRemove ( collection , id , entityName , entity );
372+ if ( statistics .isStatisticsEnabled () ) {
373+ statistics .removeCollection ( role );
374+ }
375+ } );
376+ }
369377 }
370378
371379
@@ -430,27 +438,31 @@ public void update(String entityName, Object entity) {
430438 }
431439
432440 private void removeAndRecreateCollections (Object entity , Object id , EntityPersister persister ) {
433- forEachOwnedCollection ( entity , id , persister ,
434- (descriptor , collection ) -> {
435- firePreUpdate ( collection , descriptor );
436- final EventMonitor eventMonitor = getEventMonitor ();
437- final DiagnosticEvent event = eventMonitor .beginCollectionRemoveEvent ();
438- boolean success = false ;
439- try {
440- // TODO: can we do better here?
441- descriptor .remove ( id , this );
442- descriptor .recreate ( collection , id , this );
443- success = true ;
444- }
445- finally {
446- eventMonitor .completeCollectionRemoveEvent ( event , id , descriptor .getRole (), success , this );
447- }
448- firePostUpdate ( collection , descriptor );
449- final StatisticsImplementor statistics = getFactory ().getStatistics ();
450- if ( statistics .isStatisticsEnabled () ) {
451- statistics .updateCollection ( descriptor .getRole () );
452- }
453- } );
441+ if ( persister .hasOwnedCollections () ) {
442+ final String entityName = persister .getEntityName ();
443+ final EventMonitor eventMonitor = getEventMonitor ();
444+ final StatisticsImplementor statistics = getFactory ().getStatistics ();
445+ forEachOwnedCollection ( entity , id , persister ,
446+ (descriptor , collection ) -> {
447+ final String role = descriptor .getRole ();
448+ firePreUpdate ( collection , id , entityName , entity );
449+ final DiagnosticEvent event = eventMonitor .beginCollectionRemoveEvent ();
450+ boolean success = false ;
451+ try {
452+ // TODO: can we do better here?
453+ descriptor .remove ( id , this );
454+ descriptor .recreate ( collection , id , this );
455+ success = true ;
456+ }
457+ finally {
458+ eventMonitor .completeCollectionRemoveEvent ( event , id , role , success , this );
459+ }
460+ firePostUpdate ( collection , id , entityName , entity );
461+ if ( statistics .isStatisticsEnabled () ) {
462+ statistics .updateCollection ( role );
463+ }
464+ } );
465+ }
454466 }
455467
456468 @ Override
@@ -635,44 +647,44 @@ protected void firePostDelete(Object entity, Object id, EntityPersister persiste
635647 }
636648
637649 // Hibernate Reactive may need to call this
638- protected void firePreRecreate (PersistentCollection <?> collection , CollectionPersister persister ) {
650+ protected void firePreRecreate (PersistentCollection <?> collection , Object id , String entityName , Object owner ) {
639651 eventListenerGroups .eventListenerGroup_PRE_COLLECTION_RECREATE .fireLazyEventOnEachListener (
640- () -> new PreCollectionRecreateEvent ( persister , collection , null ),
652+ () -> new PreCollectionRecreateEvent ( collection , id , entityName , owner ),
641653 PreCollectionRecreateEventListener ::onPreRecreateCollection );
642654 }
643655
644656 // Hibernate Reactive may need to call this
645- protected void firePreUpdate (PersistentCollection <?> collection , CollectionPersister persister ) {
657+ protected void firePreUpdate (PersistentCollection <?> collection , Object id , String entityName , Object owner ) {
646658 eventListenerGroups .eventListenerGroup_PRE_COLLECTION_UPDATE .fireLazyEventOnEachListener (
647- () -> new PreCollectionUpdateEvent ( persister , collection , null ),
659+ () -> new PreCollectionUpdateEvent ( collection , id , entityName , owner ),
648660 PreCollectionUpdateEventListener ::onPreUpdateCollection );
649661 }
650662
651663 // Hibernate Reactive may need to call this
652- protected void firePreRemove (PersistentCollection <?> collection , Object owner , CollectionPersister persister ) {
664+ protected void firePreRemove (PersistentCollection <?> collection , Object id , String entityName , Object owner ) {
653665 eventListenerGroups .eventListenerGroup_PRE_COLLECTION_REMOVE .fireLazyEventOnEachListener (
654- () -> new PreCollectionRemoveEvent ( persister , collection , null , owner ),
666+ () -> new PreCollectionRemoveEvent ( collection , id , entityName , owner ),
655667 PreCollectionRemoveEventListener ::onPreRemoveCollection );
656668 }
657669
658670 // Hibernate Reactive may need to call this
659- protected void firePostRecreate (PersistentCollection <?> collection , CollectionPersister persister ) {
671+ protected void firePostRecreate (PersistentCollection <?> collection , Object id , String entityName , Object owner ) {
660672 eventListenerGroups .eventListenerGroup_POST_COLLECTION_RECREATE .fireLazyEventOnEachListener (
661- () -> new PostCollectionRecreateEvent ( persister , collection , null ),
673+ () -> new PostCollectionRecreateEvent ( collection , id , entityName , owner ),
662674 PostCollectionRecreateEventListener ::onPostRecreateCollection );
663675 }
664676
665677 // Hibernate Reactive may need to call this
666- protected void firePostUpdate (PersistentCollection <?> collection , CollectionPersister persister ) {
678+ protected void firePostUpdate (PersistentCollection <?> collection , Object id , String entityName , Object owner ) {
667679 eventListenerGroups .eventListenerGroup_POST_COLLECTION_UPDATE .fireLazyEventOnEachListener (
668- () -> new PostCollectionUpdateEvent ( persister , collection , null ),
680+ () -> new PostCollectionUpdateEvent ( collection , id , entityName , owner ),
669681 PostCollectionUpdateEventListener ::onPostUpdateCollection );
670682 }
671683
672684 // Hibernate Reactive may need to call this
673- protected void firePostRemove (PersistentCollection <?> collection , Object owner , CollectionPersister persister ) {
685+ protected void firePostRemove (PersistentCollection <?> collection , Object id , String entityName , Object owner ) {
674686 eventListenerGroups .eventListenerGroup_POST_COLLECTION_REMOVE .fireLazyEventOnEachListener (
675- () -> new PostCollectionRemoveEvent ( persister , collection , null , owner ),
687+ () -> new PostCollectionRemoveEvent ( collection , id , entityName , owner ),
676688 PostCollectionRemoveEventListener ::onPostRemoveCollection );
677689 }
678690
0 commit comments