recursive algorithm: resolves Hibernate entity Foreign Key Association, resulting in JSON parsing the dead loop!

Source: Internet
Author: User

1: First talk about recursion

Recursive algorithms: recursive processes are generally implemented through functions or sub-processes. Recursive method: calls its own algorithm directly or indirectly inside a function or sub-procedure.

How to design recursive algorithm

1. Determining the recursive formula

2. Determining the boundary (end) conditions general pattern of recursionProcedure aaa (K:integer), beginif k=1 then (boundary condition and necessary operation) else Beginaaa (k-1);(repetitive operation); end;end; 2: Application Scenario Organization table: organizes a tree structure that contains parent and child nodes in an organization entity. It also contains the user collection, which is the mapping relationship between the user and the organization to establish N:M.
User table:


I'm using the RESTful API to get the tree structure of the Organization, the foreground of the Easyui tree control. Returns the JSON data for the organization, but the program is abnormal, because the organization and organization, organization, and user are nested together, resulting in JSON parsing of the returned results into the dead loop mode.

Three: Recursive solutions

sets the parent node of the organization, the child node collection set to Null, setting only one non-persisted object.

@Transient
Private set<organization> children;



recursive algorithm: resolves Hibernate entity Foreign Key Association, resulting in JSON parsing the dead loop!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.