# Hibernate - Recursive query to get object by level

Minh-Hieu Pham

Greenhorn

Posts: 1

posted 1 year ago

I have a question about Hibernate recursive GET. I have a Class:

Friends of level x of a person A is defined as below: - if x = 1, friends of level x of A are all person which have direct relation with A - if x > 1, friends of level x of A are all friends of friend of level (x-1) of A.

Exemple: - A have 3 friend A1, A2, A3 - A1 have 2 friends A1.1 and A1.2 - A2 have 1 friends A2.1 - A3 doesn't have any friend except A --> A1.1, A1.2 and A2.1 are friends of level 2 of A

The question is: use HQL or SQL or Criteria to find all relation of level x of A.

Thanks for any suggestion :-)

Friends of level x of a person A is defined as below: - if x = 1, friends of level x of A are all person which have direct relation with A - if x > 1, friends of level x of A are all friends of friend of level (x-1) of A.

Exemple: - A have 3 friend A1, A2, A3 - A1 have 2 friends A1.1 and A1.2 - A2 have 1 friends A2.1 - A3 doesn't have any friend except A --> A1.1, A1.2 and A2.1 are friends of level 2 of A

The question is: use HQL or SQL or Criteria to find all relation of level x of A.

Thanks for any suggestion :-)