I'm trying to add a reference but when I call node.getReferences() I can't see it.
I've tried creating a simple example -> create 2 nodes under root and reference one from the other. That works fine.
In my working code it doesn't. I'm guessing it's got something to do with versioning but I can' find any doc's explaining what's going on. Let me explain the structure
Root
|__project node
|
|__ node 1
|
|__ node 2
All nodes have mix:versionable and mix:referenceble.
Bit of code...
node1.checkout();
node2.checkout();
node2.setProperty("ref to node1", node1);
session.save();
if (!node1.getReferences().hasNext())
System.out.println("No references");
I've tried removing the checkout's and the save but all to no avail.
Any comments or recommended reading appreciated.
Ted.
The code you listed should work as you expect. Are you using some remoting layer (RMI, WebDAV, etc.) that might have a bug in the way references are handled?
You can try for example the following code with a local Jackrabbit instance:
Node root = session.getRootNode().addNode("test");
Node node1 = root.addNode("node1");
node1.addMixin("mix:referenceable");
Node node2 = root.addNode("node2");
node2.setProperty("reference", node1);
session.save();
System.out.println("References to " + node1.getPath() + ":");
for (Property reference : JcrUtils.getReferences(node1)) {
System.out.println("- " + reference.getPath());
}
It prints out the following:
References to /test/node1:
- /test/node2/reference