Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to query in a recursive way using QueryDSL #2150

Closed
beamofsoul opened this issue May 22, 2017 · 3 comments
Closed

How to query in a recursive way using QueryDSL #2150

beamofsoul opened this issue May 22, 2017 · 3 comments

Comments

@beamofsoul
Copy link

beamofsoul commented May 22, 2017

Hi there,

I am new to QueryDSL and struggling to figure out how to query in a recursive way.
Let us say, I have an entity/datamodel which looks like:

public class Department {
	private Long id;
	private Department parent;
}

I want to query all of children departments (include children's children and so on) by a department id in a recursive way with QueryDSL (using 4.1.4).
I am using JPAQuery object to execute the common queries, and read through the latest reference doc still cannot find the answer, so what should I do to make it work ?

Please help.
Thanks in advance.

@Maze-fr
Copy link

Maze-fr commented Jul 12, 2017

Did you try to use @OneToMany and @ManyToOne like with any other table joining ?

@johnjaylward
Copy link

@beamofsoul , SQL and relational databases in general do not handle recursive structures well without some help and extra meta-data stored in the table.

The following article is very good on handling it specifically in MySQL, but it can be extrapolated to other database technologies as well.

http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/

@stale
Copy link

stale bot commented Jun 3, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants