From 863f6a8fb7b7779e0038f523742b83cb00af7915 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Wed, 24 Feb 2010 00:11:24 +0000 Subject: [PATCH] HHH-4948 : Session.flush() does not always cascade save or update to read-only or immutable entities git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18866 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../hibernate/event/def/DefaultAutoFlushEventListener.java | 3 ++- .../org/hibernate/event/def/DefaultFlushEventListener.java | 7 ++++--- .../java/org/hibernate/test/immutable/ImmutableTest.java | 2 -- 3 files changed, 6 insertions(+), 6 deletions(-) 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