Transitioning this over from the GH discussion: We added the recursive CTE construct to model the canonical way to do recursive queries in HQL, but I think it would be nice to extend this a bit. Here are a few ideas. The idea is that we introduce a new kind of join, a recursive join, which we translate to a recursive CTE. Recursive joins would only be allowed on self referencing @ManyToOne/@OneToMany(mappedBy) associations. If we want to support EAGER fetching of recursive associations we would probably need some sort of @RecursiveParent/@RecursiveChildren annotation to mark associations in an entity model, so that we can generate the proper query, but I guess we can ignore that for now. The really interesting part is when join fetching collections e.g. from Entity1 a recursive join fetch a.children, as that has an implication on the Fetch we generate and how we process results, since all nested collection will become initialized this way. |