Project

General

Profile

Actions

bug #10101

open

Correct mapping and handling of sorted tree structures

Added by Andreas Müller almost 2 years ago. Updated over 1 year ago.

Status:
In Progress
Priority:
Priority14
Category:
cdmlib
Target version:
Start date:
Due date:
% Done:

20%

Estimated time:
Severity:
normal
Found in Version:

Description

We currently have 3 sorted tree structures in the CDM: Classifications, TermTrees and PolytomousKeys.

The correct mapping and handling of sorted tree structures is difficult. Children are modelled as Lists which usually is best handled with an @OrderColumn annotation (#3722) and a bidirectional mapping with orphanRemoval. If orphanRemoval is not used orphaned (deleted) children need to be deleted manually, otherwise they stay in the database and, in the worst case, have the same parent_id and sortindex if parent_id is not correctly removed by bidirectionality imlementation. This leads to kind of duplicates and, even worse, to gaps in the sortindex when the tree structure is persisted via merge. Gaps in the sortindexes (e.g. 0 followed by 3) lead to null values when the list is reloaded (#5536, #8127).

However, though orphanRemoval handles this best for Lists it is not good for (recursive) trees because moving a subtree to another parent then requires to clone the full subtree as not only the root but also all its children will be automatically deleted by hibernate via orphanRemoval. For large trees this is unwanted behavior and also for smaller trees cloning is not a great solution.

So a better solution is to manually remove the nodes if they are not used anymore. We tried to do this automatically for merge via the PostMergeEntityListener but still without success. See comments in #note-7.

Therefore a new merge method was created to merge together with the entities that should be deleted. This seems to work.

Note: To avoid the sortindex still has a gap for some reason we have to touch the children list somehow before commit. This is currently done in the PostMergeEntityListener.

Related tests are: PolytomousKeyNodeServiceTest.testMergeXXX() (maybe will move to PolytomousKeyServiceTest partly)


Related issues

Related to EDIT - task #3722: Using @OrderColumn does not work in treesClosedAndreas Müller05/23/202205/27/2022

Actions
Related to EDIT - task #8127: [Reminder] to check if Hibernate Null Value bug still existsDiscussedAndreas Müller05/23/202205/27/2022

Actions
Related to EDIT - bug #5211: Error when creating new taxon /problem with sortindex in taxon treeIn ProgressAndreas Müller

Actions
Actions

Also available in: Atom PDF