What's the best way to create one-to-many relations between nodes?
1. Add a property with the path to a related nodes as a String.
#1 could easily break if a related node was deleted. In a relational db, it's easy to add relationships so that deleting a related node causes it's relationships to be automatically cleaned up. Seems I'd have to write that cleanup code myself in option #1.
Are there other options (#2, #3, ...) or is #1 the only way to relate nodes in a JCR?
Finally found a good explanation of handling relationships here: http://jackrabbit.510166.n4.nabble.com/Linking-JCR-Nodes-td3308096.html
Here's a summary:
In most cases, soft references using path strings is much better than hard references. See also http://wiki.apache.org/jackrabbit/DavidsModel (rule #7).
These are the options for referencing in JCR 2.0, from hardest to softest variant:
(1) REFERENCE: Hard reference, using UUID internally, enforced, with Node.getReferences() automatically giving you all nodes pointing to this node:
(2) WEAKREFERENCE: Weak reference, using UUID internally, not enforced, with Node.getWeakReferences() automatically giving you all nodes pointing to this node:
(3) PATH: Soft reference, using a path string, only the path syntax is validated, but existence of the target is not enforced:
(4) STRING: Soft reference, using a path string, plain string property, nothing is enforced:
The post noted above recommends going for (3) or (4). Probably it's my relational db background and distrust of JCR at this point, but I still prefer the hard enforced relationships...