How would you persist root nodes of custom tree structures in such a way that they could be retrieved with a simple SELECT ?
Pseudo-code
class Node {
Long id;
String label;
Node parent;
List<Node> children;
}
Edit: Tables could be as follows. Feel free to suggest improvement.
CREATE TABLE NODES(
ID INTEGER NOT NULL UNIQUE,
LABEL VARCHAR(255)
);
CREATE TABLE PARENTS_CHILDREN(
PARENT_ID INTEGER NOT NULL,
CHILD_ID INTEGER NOT NULL
);
You could use an adjacency list:
The root nodes can be found with
WHERE parent IS NULL.