Issue Type: Bug Bug
Affects Versions: 4.1.10
Assignee: Unassigned
Components: query-criteria
Created: 25/Feb/13 3:15 PM
Description:

The following link: http://www.tikalk.com/java/load-a-tree-with-jpa-and-hibernate
describes how to load a Recursively structured Composite Object pattern from a single table.
Hibernate generates this object quite well, and does a fine job with both Lazy as well as Eager loading of the children -
If however you try to have an Entity with the following bi-directional relationship:

Public Class CompositeElement {
...
@ManyToOne
@JoinColumn(name = "parent_id")
public CompositeElement getParent() { return parent; }

@OneToMany(mappedBy = "parent", targetEntity = CompositeElement.class, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
public List<CompositeElement> getChildren() { return children; }

but try to override the fetch behavior in a particular use case for example using a Criteria:

criteria.setFetchMode("children", FetchMode.JOIN);

The query which is generated is not correct for postgres:
from CompositeElement compositee0_
left outer join CompositeElement compositee2_ on compositee1_.parent_id=compositee2_.id

Which will only go one level deep into the recursive structure.

This should generate a with recursion query for postgres.

Environment: I am running in the context of Tomcat 7.0 + Spring 3.2 + using JPA annotations
java version "1.7.0_13"
Project: Hibernate ORM
Labels: criteria composite recursive postgres child parent node tree
Priority: Major Major
Reporter: Damon Weinstein
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira