Jackrabbit - node.getReferences() not returning anything

痴心易碎 提交于 2019-12-10 11:38:12

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/7474222/jackrabbit-node-getreferences-not-returning-anything

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!