SlideShare a Scribd company logo
Hello,
I have an entity class
@Entity
@Table(name = "employees")
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "manager_id")
private Employee manager;
// getters and setters
}
It has a self referencing (hierarchal)
and I have a repository to return the parents(managers) and the children(employees) under them.
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
@Query(nativeQuery = true,
value = "WITH RECURSIVE manager_tree(id, name) AS (" +
" SELECT id, name " +
" FROM employees " +
" WHERE manager_id IS NULL " +
"UNION ALL " +
" SELECT e.id, e.name " +
" FROM employees e " +
" JOIN manager_tree mt ON mt.id = e.manager_id " +
") " +
"SELECT * FROM manager_tree")
List<Employee> findTopLevelManagers();
}
I want this query to be written using Spring JPA (native queries are not allowed), so could any
expert help me by rewrite the query using Spring JPA (native queries are not allowed)
and the manager of the managers their id is 1 not null ( WHERE manager_id IS NULL ) so I hope
the expert change this line also.

More Related Content

PDF
7- Match the astronomer to his accomplishment a- Ptolemy i- Made very.pdf
a2zmobiles
 
PDF
7- In a multiple linear regression model y-X+-XN(0-2In)- the OLS estim (1).pdf
a2zmobiles
 
PDF
7- In addition to a pH imbalance- prolonged vomiting is also causing D.pdf
a2zmobiles
 
PDF
7- The temperature at which a certain substance boils is normally dist.pdf
a2zmobiles
 
PDF
7- The length of time necessary to complete a specific task is exponen.pdf
a2zmobiles
 
PDF
7- The following data have been collected for a British healthcare IT.pdf
a2zmobiles
 
PDF
7- Many news organizations conduct polls asking adults in the United S.pdf
a2zmobiles
 
PDF
7- Calculate - DV for the following foed label (For carbohydrate and F.pdf
a2zmobiles
 
7- Match the astronomer to his accomplishment a- Ptolemy i- Made very.pdf
a2zmobiles
 
7- In a multiple linear regression model y-X+-XN(0-2In)- the OLS estim (1).pdf
a2zmobiles
 
7- In addition to a pH imbalance- prolonged vomiting is also causing D.pdf
a2zmobiles
 
7- The temperature at which a certain substance boils is normally dist.pdf
a2zmobiles
 
7- The length of time necessary to complete a specific task is exponen.pdf
a2zmobiles
 
7- The following data have been collected for a British healthcare IT.pdf
a2zmobiles
 
7- Many news organizations conduct polls asking adults in the United S.pdf
a2zmobiles
 
7- Calculate - DV for the following foed label (For carbohydrate and F.pdf
a2zmobiles
 

More from a2zmobiles (20)

PDF
7- With the help of suitable examples- Explain how the application of.pdf
a2zmobiles
 
PDF
7- A taxpayer's wife died in 2021 and he has not remarried- He has two.pdf
a2zmobiles
 
PDF
7- In his book- Alfred Wegener presented many lines of evidence that E.pdf
a2zmobiles
 
PDF
7- In humans- the allele for normal blood clotting- H- is dominant to.pdf
a2zmobiles
 
PDF
7- Examine the map of the Murky Mists Mountain- - D- INote tne strike.pdf
a2zmobiles
 
PDF
7- 7- Caleulating Returns and Variability (LO1) Usine the followine re.pdf
a2zmobiles
 
PDF
7- A perpetuity-immediate pays 1500 per year- Alice receives the first.pdf
a2zmobiles
 
PDF
7- A cohort study employs a- Subjects known at the start to have the d.pdf
a2zmobiles
 
PDF
7- When I present the German Tank Problem- the most popular proposals.pdf
a2zmobiles
 
PDF
7- (Microsoft Visual Basic) Display a triangle Hints- The following co.pdf
a2zmobiles
 
PDF
HELPPP Which of the following are differences in the recommendations.pdf
a2zmobiles
 
PDF
Hemophilia is due to a recessive allele (h) linked to the X chromosome (1).pdf
a2zmobiles
 
PDF
Henry Ford- majority shareholder of the Ford Motor Company- announced.pdf
a2zmobiles
 
PDF
hen should a company use the fair value method to account for its equi.pdf
a2zmobiles
 
PDF
HELPPPO A- B- What is the correct order of events that take plac.pdf
a2zmobiles
 
PDF
help please!thanks Ear Shape In pigs- erect ears are dominant (E) to d.pdf
a2zmobiles
 
PDF
HELP PLEASE A- B- What event is indicative of transcription init.pdf
a2zmobiles
 
PDF
Help create the vcipher-h and vcipher-cc files for the vigenere cipher.pdf
a2zmobiles
 
PDF
Help implement BST- The code must follow the instruction below as well.pdf
a2zmobiles
 
PDF
Help me create a use case diagram for this use case- Use case title-.pdf
a2zmobiles
 
7- With the help of suitable examples- Explain how the application of.pdf
a2zmobiles
 
7- A taxpayer's wife died in 2021 and he has not remarried- He has two.pdf
a2zmobiles
 
7- In his book- Alfred Wegener presented many lines of evidence that E.pdf
a2zmobiles
 
7- In humans- the allele for normal blood clotting- H- is dominant to.pdf
a2zmobiles
 
7- Examine the map of the Murky Mists Mountain- - D- INote tne strike.pdf
a2zmobiles
 
7- 7- Caleulating Returns and Variability (LO1) Usine the followine re.pdf
a2zmobiles
 
7- A perpetuity-immediate pays 1500 per year- Alice receives the first.pdf
a2zmobiles
 
7- A cohort study employs a- Subjects known at the start to have the d.pdf
a2zmobiles
 
7- When I present the German Tank Problem- the most popular proposals.pdf
a2zmobiles
 
7- (Microsoft Visual Basic) Display a triangle Hints- The following co.pdf
a2zmobiles
 
HELPPP Which of the following are differences in the recommendations.pdf
a2zmobiles
 
Hemophilia is due to a recessive allele (h) linked to the X chromosome (1).pdf
a2zmobiles
 
Henry Ford- majority shareholder of the Ford Motor Company- announced.pdf
a2zmobiles
 
hen should a company use the fair value method to account for its equi.pdf
a2zmobiles
 
HELPPPO A- B- What is the correct order of events that take plac.pdf
a2zmobiles
 
help please!thanks Ear Shape In pigs- erect ears are dominant (E) to d.pdf
a2zmobiles
 
HELP PLEASE A- B- What event is indicative of transcription init.pdf
a2zmobiles
 
Help create the vcipher-h and vcipher-cc files for the vigenere cipher.pdf
a2zmobiles
 
Help implement BST- The code must follow the instruction below as well.pdf
a2zmobiles
 
Help me create a use case diagram for this use case- Use case title-.pdf
a2zmobiles
 
Ad

Recently uploaded (20)

PPTX
CDH. pptx
AneetaSharma15
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PDF
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
PDF
Study Material and notes for Women Empowerment
ComputerScienceSACWC
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PPTX
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
CDH. pptx
AneetaSharma15
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
Study Material and notes for Women Empowerment
ComputerScienceSACWC
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
Ad

Hello- I have an entity class -Entity -Table(name - -employees-) pub.pdf

  • 1. Hello, I have an entity class @Entity @Table(name = "employees") public class Employee { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String name; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "manager_id") private Employee manager; // getters and setters } It has a self referencing (hierarchal) and I have a repository to return the parents(managers) and the children(employees) under them. public interface EmployeeRepository extends JpaRepository<Employee, Long> { @Query(nativeQuery = true, value = "WITH RECURSIVE manager_tree(id, name) AS (" + " SELECT id, name " + " FROM employees " + " WHERE manager_id IS NULL " + "UNION ALL " +
  • 2. " SELECT e.id, e.name " + " FROM employees e " + " JOIN manager_tree mt ON mt.id = e.manager_id " + ") " + "SELECT * FROM manager_tree") List<Employee> findTopLevelManagers(); } I want this query to be written using Spring JPA (native queries are not allowed), so could any expert help me by rewrite the query using Spring JPA (native queries are not allowed) and the manager of the managers their id is 1 not null ( WHERE manager_id IS NULL ) so I hope the expert change this line also.