How AI is applied across API Evangelist and APIs.io. Read my AI disclosure →
API Evangelist API Evangelist
Discovery
Learnings
Guidance
Toolbox
Alignment
API Evangelist LLC

How to rebuild a tree from PostgreSQL without duplicate nodes? [closed]

calendar_today May 29, 2026 person MARIO JOSE BARRERA LINAREZ domain spring-boot
I’m developing a Spring Boot application that stores a tree structure in PostgreSQL. The table schema is: CREATE TABLE nodes ( id BIGINT PRIMARY KEY, value VARCHAR(150), parent_id BIGINT ); Example data: 1 Management NULL 2 IT Department 1 3 Developer 2 To rebuild the tree in memory, I’m using Java Collections: private final Map > tree = new HashMap<>(); public void loadTree(List nodes) { for (NodeEntity node : nodes) { if (node.getParentId() != null) { tree.putIfAbsent(node.getParentId(), new ArrayList<>()); tree.get(node.getParentId()).add(node.getId()); } } } The problem is that
open_in_new Read original post