Saving Tree Structures in Databases

I am using Hibernate / Spring and a MySQL database to manage data.

I am currently displaying a tree structure in JTable. A tree can have several branches, in turn, a branch can have several branches (up to nine levels) again or have leaves. Recently, I have had performance issues as soon as I want to create new branches at deeper levels.

At this time, the branch has a foreign key for its parent. The domainobject has access to its parent object by calling getParent (), which returns the parent branch. The deeper the level, the more time it takes to create a new branch.

The Microbenchmark results for creating a new branch are as follows:

Level 1: 32 ms. Level 3: 80 ms. Level 9: 232 ms.

Obviously, the level is responsible for this (which means the number of parents). So I wanted to ask if there are any appendages to solve this problem. I do not understand why Hibernate should know about the whole tree of objects (all parents to the root) when creating a new branch. But as far as I know, this may be the only reason for the delay in creating a new branch, because the branch has no other relations with other objects.

I would really appreciate any workarounds or suggestions.

hello ymene

+3
source share
4 answers

, - ? . , " " , java.util.Set.

ArrayList, , hibernate .

. lazy = "false" , , .

"inverse" . , , . , .

google for for inverse, .

.

+2

, Hibernate . . , , , " ", , (, ). , , , . , , Hibernate .

+1

SQL, JTable (, - XStream). , , .

+1

, , XML MySQL. . XML MySQL, , , (SQL Server DB2, , , , Oracle ). , , , , (, ).

+1

Source: https://habr.com/ru/post/1746161/


All Articles