diff --git a/framework/entity/entitydef/entitymodel_test.xml b/framework/entity/entitydef/entitymodel_test.xml
index 676d2db0c6..35caba2ee2 100644
--- a/framework/entity/entitydef/entitymodel_test.xml
+++ b/framework/entity/entitydef/entitymodel_test.xml
@@ -70,6 +70,27 @@ under the License.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java b/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java
index bef6c0bc5f..21b8b28246 100644
--- a/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java
+++ b/framework/entity/src/org/ofbiz/entity/cache/EntityCache.java
@@ -18,11 +18,14 @@
*******************************************************************************/
package org.ofbiz.entity.cache;
+import java.util.Iterator;
+
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.cache.UtilCache;
import org.ofbiz.entity.GenericPK;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityCondition;
+import org.ofbiz.entity.model.ModelEntity;
public class EntityCache extends AbstractCache {
public static final String module = EntityCache.class.getName();
@@ -77,6 +80,14 @@ public class EntityCache extends AbstractCache {
if (Debug.verboseOn()) Debug.logVerbose("Removing from EntityCache with PK [" + pk + "], will remove from this cache: " + (entityCache == null ? "[No cache found to remove from]" : entityCache.getName()), module);
if (entityCache == null) return null;
GenericValue retVal = entityCache.remove(pk);
+ ModelEntity model = pk.getModelEntity();
+ if (model != null) {
+ Iterator it = model.getViewConvertorsIterator();
+ while (it.hasNext()) {
+ String targetEntityName = it.next();
+ UtilCache.clearCache(getCacheName(targetEntityName));
+ }
+ }
if (Debug.verboseOn()) Debug.logVerbose("Removing from EntityCache with PK [" + pk + "], found this in the cache: " + retVal, module);
return retVal;
}
diff --git a/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java b/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java
index c26b9a6694..91bb56eb7e 100644
--- a/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java
+++ b/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java
@@ -218,7 +218,20 @@ public class EntityTestSuite extends EntityTestCase {
testValue.remove();
testList = delegator.findList("TestingType", testCondition, null, null, null, true);
assertEquals("Delegator findList returned empty list", 0, testList.size());
- // TODO: Test view entities.
+ // Test view entities in the pk cache - updating an entity should clear pk caches for all view entities containing that entity.
+ testValue = delegator.create("TestingSubtype", "testingTypeId", "TEST-9", "subtypeDescription", "Testing Subtype #9");
+ assertNotNull("TestingSubtype created", testValue);
+ // Confirm member entity appears in the view
+ testValue = delegator.findOne("TestingViewPks", true, "testingTypeId", "TEST-9");
+ assertEquals("View retrieved from cache has the correct member description", "Testing Subtype #9", testValue.getString("subtypeDescription"));
+ testValue = delegator.findOne("TestingSubtype", true, "testingTypeId", "TEST-9");
+ // Modify member entity
+ testValue = (GenericValue) testValue.clone();
+ testValue.put("subtypeDescription", "New Testing Subtype #9");
+ testValue.store();
+ // Check if cached view contains the modification
+ testValue = delegator.findOne("TestingViewPks", true, "testingTypeId", "TEST-9");
+ assertEquals("View retrieved from cache has the correct member description", "New Testing Subtype #9", testValue.getString("subtypeDescription"));
}
/*