diff --git a/core/src/main/java/org/hibernate/event/def/DefaultAutoFlushEventListener.java b/core/src/main/java/org/hibernate/event/def/DefaultAutoFlushEventListener.java index ee6864ad09..145c60648f 100644 --- a/core/src/main/java/org/hibernate/event/def/DefaultAutoFlushEventListener.java +++ b/core/src/main/java/org/hibernate/event/def/DefaultAutoFlushEventListener.java @@ -92,7 +92,8 @@ public class DefaultAutoFlushEventListener extends AbstractFlushingEventListener private boolean flushMightBeNeeded(final EventSource source) { return !source.getFlushMode().lessThan(FlushMode.AUTO) && source.getDontFlushFromFind() == 0 && - source.getPersistenceContext().hasNonReadOnlyEntities(); + ( source.getPersistenceContext().getEntityEntries().size() > 0 || + source.getPersistenceContext().getCollectionEntries().size() > 0 ); } } diff --git a/core/src/main/java/org/hibernate/event/def/DefaultFlushEventListener.java b/core/src/main/java/org/hibernate/event/def/DefaultFlushEventListener.java index 14c239c503..7122c6af3d 100644 --- a/core/src/main/java/org/hibernate/event/def/DefaultFlushEventListener.java +++ b/core/src/main/java/org/hibernate/event/def/DefaultFlushEventListener.java @@ -44,8 +44,9 @@ public class DefaultFlushEventListener extends AbstractFlushingEventListener imp */ public void onFlush(FlushEvent event) throws HibernateException { final EventSource source = event.getSession(); - if ( source.getPersistenceContext().hasNonReadOnlyEntities() ) { - + if ( source.getPersistenceContext().getEntityEntries().size() > 0 || + source.getPersistenceContext().getCollectionEntries().size() > 0 ) { + flushEverythingToExecutions(event); performExecutions(source); postFlush(source); @@ -53,7 +54,7 @@ public class DefaultFlushEventListener extends AbstractFlushingEventListener imp if ( source.getFactory().getStatistics().isStatisticsEnabled() ) { source.getFactory().getStatisticsImplementor().flush(); } - + } } } diff --git a/testsuite/src/test/java/org/hibernate/test/immutable/ImmutableTest.java b/testsuite/src/test/java/org/hibernate/test/immutable/ImmutableTest.java index 5ef8e55f04..3c06252c99 100755 --- a/testsuite/src/test/java/org/hibernate/test/immutable/ImmutableTest.java +++ b/testsuite/src/test/java/org/hibernate/test/immutable/ImmutableTest.java @@ -280,7 +280,6 @@ public class ImmutableTest extends FunctionalTestCase { // c was loaded into s, so it should be read-only assertTrue( s.isReadOnly( c ) ); c.setCustomerName("foo bar"); - c.getVariations().add( new ContractVariation(3, c) ); cv1 = (ContractVariation) c.getVariations().iterator().next(); cv1.setText("blah blah"); // cv1 and cv2 were loaded into s by hibernate, so they should be read-only @@ -350,7 +349,6 @@ public class ImmutableTest extends FunctionalTestCase { // c was loaded into s, so it should be read-only assertTrue( s.isReadOnly( c ) ); c.setCustomerName("foo bar"); - c.getVariations().add( new ContractVariation(3, c) ); cv1 = (ContractVariation) c.getVariations().iterator().next(); cv1.setText("blah blah"); // cv1 and cv2 were loaded into s by hibernate, so they should be read-only