Master data management Β· features 286-305
πŸ›’οΈ SQL Server Β· MasterDataLabDB
πŸ—‚οΈ

286Categories

Product / document categories arranged as a tree: each category may have a parent.

Try it

Category tree

Built in memory from parent_id by CategoryService.tree()

Tip: edit a category and pick a new Parent to move it - try putting a category under its own child to see the loop check.

# Code Name Parent Icon Sort order Status
1 ELEC Electronics β€” πŸ’» 1 Active ✏️
5 ELEC-COMP Computers ELEC - Electronics πŸ–₯️ 1 Active ✏️
14 ELEC-COMP-LAP Laptops ELEC-COMP - Computers πŸ’» 1 Active ✏️
8 HOME-FURN Furniture HOME - Home & Living πŸͺ‘ 1 Active ✏️
10 OFFICE-PAPER Paper OFFICE - Office Supplies πŸ“„ 1 Active ✏️
12 SERV-INST Installation SERV - Services πŸ”§ 1 Active ✏️
15 ELEC-COMP-DESK Desktops ELEC-COMP - Computers πŸ–₯️ 2 Active ✏️
6 ELEC-PHONE Phones & Tablets ELEC - Electronics πŸ“± 2 Active ✏️
2 HOME Home & Living β€” πŸ›‹οΈ 2 Active ✏️
9 HOME-KIT Kitchen HOME - Home & Living 🍳 2 Active ✏️
11 OFFICE-WRITE Writing Tools OFFICE - Office Supplies ✏️ 2 Active ✏️
13 SERV-MAINT Maintenance SERV - Services 🧰 2 Active ✏️
7 ELEC-ACC Accessories ELEC - Electronics 🎧 3 Active ✏️
16 ELEC-COMP-MON Monitors ELEC-COMP - Computers πŸ–΅ 3 Active ✏️
3 OFFICE Office Supplies β€” πŸ“Ž 3 Active ✏️
Showing 1–15 of 16
πŸŽ“ Learn: how this master is built table category
  • Self-referencing table: category.parent_id β†’ category.id (adjacency list).
  • CategoryService.tree() loads all rows once and builds the tree in memory - no recursive SQL needed.
  • CategoryService.validate() walks up the parents to stop loops (A under B under A).
Entity
domain/Category.java
Repository
repo/CategoryRepository.java
Definition
MasterRegistry: "categories"
Page / form
web/MasterController.java
Try-it panel
templates/tools/category-tree.html
REST API
GET /api/masters/categories?q=comp
-- the whole tree with a recursive CTE
WITH tree AS (
  SELECT id, code, name, parent_id, 0 AS depth, CAST(name AS NVARCHAR(400)) AS path
  FROM category WHERE parent_id IS NULL
  UNION ALL
  SELECT c.id, c.code, c.name, c.parent_id, t.depth + 1, CAST(t.path + N' > ' + c.name AS NVARCHAR(400))
  FROM category c JOIN tree t ON c.parent_id = t.id
)
SELECT * FROM tree ORDER BY path;