开发者

Apache Jackrabbit - Duplicate Node?

开发者 https://www.devze.com 2023-03-07 00:16 出处:网络
Using Apache Jackrabbit, I created two nodes at exactly the same path root.addNode(\"hello\"); I was fully expecting the second addition to throw an ItemExistsException as described here, but it di

Using Apache Jackrabbit, I created two nodes at exactly the same path

root.addNode("hello");

I was fully expecting the second addition to throw an ItemExistsException as described here, but it didn't.

When I print out the path of the nodes to try and see what was going on, I see /hello for the first node and /hello[2] for the second node

Further, when I delete the node, a test to check for the existence of the node passes before I save the session, but after I save the session a second test of the same condition fails

session.getNode("/hello").remove(); 
assertFalse(session.nodeExists("/hello"));

s开发者_StackOverflow社区ession.save(); 

assertFalse(session.nodeExists("/hello"));

What's going on here? Is this a bug or some feature of Jackrabbit that deviates from the spec?


What you are seeing are Same Name Siblings, which is a feature of Jackrabbit and the JCR. David Nuescheler, the lead developer of JSR-170 wrote in the Jackrabbit WIKI:

While Same Name Siblings (SNS) have been introduced into the spec to allow compatibility with data structures that are designed for and expressed through XML and therefore are extremely valuable to JCR, SNS come with a substantial overhead and complexity for the repository.

...

For import of XML or interaction with existing XML SNS maybe necessary and useful but I have never used SNS, and never will in my "green field" data models.

So basically, the reason you have same name siblings to accommodate XML data where you can have multiple elements of the same name. I have seen same name sibilings used in Day's CQ WCM, but their use overall seems to be discouraged.

0

精彩评论

暂无评论...
验证码 换一张
取 消