diff --git a/src/helma/objectmodel/db/Node.java b/src/helma/objectmodel/db/Node.java index 7cae28e2..1b997956 100644 --- a/src/helma/objectmodel/db/Node.java +++ b/src/helma/objectmodel/db/Node.java @@ -1781,7 +1781,7 @@ public final class Node implements INode, Serializable { if (rel != null) { // Is a relational node stored by id but things it's a string or int. Fix it. if (rel.otherType != null && prop.getType() != Property.NODE) { - prop.convertToNodeReference(rel.otherType); + prop.convertToNodeReference(rel); } if (rel.isVirtual()) { // property was found in propMap and is a collection - this is diff --git a/src/helma/objectmodel/db/NodeManager.java b/src/helma/objectmodel/db/NodeManager.java index 60166be1..e51d896d 100644 --- a/src/helma/objectmodel/db/NodeManager.java +++ b/src/helma/objectmodel/db/NodeManager.java @@ -303,7 +303,7 @@ public final class NodeManager { return null; } else { // update primary key in cache to keep it from being flushed, see above - if (!rel.usesPrimaryKey()) { + if (!rel.usesPrimaryKey() && node.getState() != Node.TRANSIENT) { synchronized (cache) { Node old = (Node) cache.put(node.getKey(), node); @@ -1870,7 +1870,7 @@ public final class NodeManager { // if the property is a pointer to another node, change the property type to NODE if (rel.isReference() && rel.usesPrimaryKey()) { // FIXME: References to anything other than the primary key are not supported - prop.convertToNodeReference(rel.otherType); + prop.convertToNodeReference(rel); } propMap.put(rel.propName.toLowerCase(), prop); } diff --git a/src/helma/objectmodel/db/Property.java b/src/helma/objectmodel/db/Property.java index 7550e329..71a4738f 100644 --- a/src/helma/objectmodel/db/Property.java +++ b/src/helma/objectmodel/db/Property.java @@ -311,11 +311,15 @@ public final class Property implements IProperty, Serializable, Cloneable, Compa /** * * - * @param dbm ... + * @param rel the Relation */ - public void convertToNodeReference(DbMapping dbm) { + public void convertToNodeReference(Relation rel) { if ((value != null) && !(value instanceof NodeHandle)) { - value = new NodeHandle(new DbKey(dbm, value.toString())); + if (rel.usesPrimaryKey()) { + value = new NodeHandle(new DbKey(rel.otherType, value.toString())); + } else { + value = new NodeHandle(new MultiKey(rel.otherType, rel.getKeyParts(node))); + } } type = NODE; diff --git a/src/helma/objectmodel/db/Relation.java b/src/helma/objectmodel/db/Relation.java index 776d85e0..adf08276 100644 --- a/src/helma/objectmodel/db/Relation.java +++ b/src/helma/objectmodel/db/Relation.java @@ -1207,6 +1207,11 @@ public final class Relation { Property prop = home.getProperty(cnst.localProperty()); if (prop != null) { child.set(crel.propName, prop.getValue(), prop.getType()); + } else { + prop = child.getProperty(cnst.foreignProperty(child.getDbMapping())); + if (prop != null) { + home.set(cnst.localProperty(), prop.getValue(), prop.getType()); + } } } }