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..