diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java index 1a56887bd3..14c837ea6d 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java @@ -1162,9 +1162,7 @@ public class StatefulPersistenceContext implements PersistenceContext { //not found in case, proceed // iterate all the entities currently associated with the persistence context. - Iterator> entities = IdentityMap.entriesIterator( entityEntries ); - while ( entities.hasNext() ) { - final Map.Entry me = entities.next(); + for ( Entry me : IdentityMap.entriesIterable( entityEntries ) ) { final EntityEntry entityEntry = me.getValue(); // does this entity entry pertain to the entity persister in which we are interested (owner)? if ( persister.isSubclassEntityName( entityEntry.getEntityName() ) ) { @@ -1286,9 +1284,7 @@ public class StatefulPersistenceContext implements PersistenceContext { } //Not found in cache, proceed - Iterator> entities = IdentityMap.entriesIterator( entityEntries ); - while ( entities.hasNext() ) { - Map.Entry me = entities.next(); + for ( Entry me : IdentityMap.entriesIterable( entityEntries ) ) { EntityEntry ee = me.getValue(); if ( persister.isSubclassEntityName( ee.getEntityName() ) ) { Object instance = me.getKey(); diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java index 8d607ac23f..1a950fd073 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java @@ -186,10 +186,9 @@ public abstract class AbstractFlushingEventListener implements Serializable { LOG.debug( "Dirty checking collections" ); - Iterator> entriesIterator = IdentityMap.entriesIterator( persistenceContext.getCollectionEntries() ); - while ( entriesIterator.hasNext() ) { - Map.Entry e = entriesIterator.next(); - e.getValue().preFlush( e.getKey() ); + for ( Map.Entry entry : + IdentityMap.entriesIterable( (Map) persistenceContext.getCollectionEntries() )) { + entry.getValue().preFlush( entry.getKey() ); } } @@ -246,9 +245,8 @@ public abstract class AbstractFlushingEventListener implements Serializable { LOG.trace( "Processing unreferenced collections" ); - Iterator> entriesIterator = IdentityMap.entriesIterator( persistenceContext.getCollectionEntries() ); - while ( entriesIterator.hasNext() ) { - Map.Entry me = entriesIterator.next(); + for ( Map.Entry me : + IdentityMap.entriesIterable( (Map) persistenceContext.getCollectionEntries() )) { CollectionEntry ce = me.getValue(); if ( !ce.isReached() && !ce.isIgnore() ) { Collections.processUnreachableCollection( me.getKey(), session ); @@ -259,10 +257,9 @@ public abstract class AbstractFlushingEventListener implements Serializable { LOG.trace( "Scheduling collection removes/(re)creates/updates" ); - entriesIterator = IdentityMap.entriesIterator( persistenceContext.getCollectionEntries() ); ActionQueue actionQueue = session.getActionQueue(); - while ( entriesIterator.hasNext() ) { - Map.Entry me = entriesIterator.next(); + for ( Map.Entry me : + IdentityMap.entriesIterable( (Map) persistenceContext.getCollectionEntries() )) { PersistentCollection coll = me.getKey(); CollectionEntry ce = me.getValue(); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/IdentityMap.java b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/IdentityMap.java index 9c91a5536d..1183fbb75c 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/IdentityMap.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/IdentityMap.java @@ -90,8 +90,8 @@ public final class IdentityMap implements Map { return ( (IdentityMap) map ).entryArray(); } - public static Iterator> entriesIterator(Map map) { - return ( (IdentityMap) map ).entryList().iterator(); + public static Iterable> entriesIterable(Map map) { + return ( (IdentityMap) map ).entryList(); } public static Iterator keyIterator(Map map) {