diff --git a/Frameworks/Core/ERExtensions/Sources/er/extensions/eof/ERXGenericRecord.java b/Frameworks/Core/ERExtensions/Sources/er/extensions/eof/ERXGenericRecord.java
index 29fa7a00c3c..740ebfc0020 100644
--- a/Frameworks/Core/ERExtensions/Sources/er/extensions/eof/ERXGenericRecord.java
+++ b/Frameworks/Core/ERExtensions/Sources/er/extensions/eof/ERXGenericRecord.java
@@ -81,6 +81,8 @@ public class ERXGenericRecord extends EOGenericRecord implements ERXGuardedObjec
* Java Object Serialization Spec
*/
private static final long serialVersionUID = 1L;
+
+ private transient EOEntity _entity;
/** holds all subclass related Logger's */
private static final NSMutableDictionary classLogs = new NSMutableDictionary();
@@ -633,7 +635,10 @@ public NSArray primaryKeyAttributeNames() {
* @return EOEntity for the current object
*/
public EOEntity entity() {
- return ERXEOAccessUtilities.entityNamed(editingContext(), entityName());
+ if(_entity == null) {
+ _entity = ERXEOAccessUtilities.entityNamed(editingContext(), entityName());
+ }
+ return _entity;
}
/** caches the primary key dictionary for the given object */
@@ -1064,17 +1069,19 @@ public boolean isValidatedWhenNested() {
*/
@Override
public Object handleQueryWithUnboundKey(String key) {
- NSDictionary pkDict = EOUtilities.primaryKeyForObject(editingContext(), this);
- if (pkDict == null) {
- // This will be the case for new unsaved objects, so just
- // check if the user was using a key that is valid as a primary key attribute
- if (entity().primaryKeyAttributeNames().contains(key)) {
- // Valid hidden PK key, so return null since PK is still essentially null.
+ // Handles primary key attribute values
+ if(entity().primaryKeyAttributeNames().contains(key)) {
+ // Deleted object. Return null.
+ if(editingContext() == null) {
+ return null;
+ }
+ NSDictionary pkDict = EOUtilities.primaryKeyForObject(editingContext(), this);
+ // New object. Return null.
+ if(pkDict == null) {
return null;
}
- } else if (pkDict.allKeys().contains(key)) {
- // Valid PK key, so return the atribute value.
- return pkDict.valueForKey(key);
+ // Return value for key
+ return pkDict.objectForKey(key);
}
return super.handleQueryWithUnboundKey(key);
}