I have one issue with retrieval Parent/Child relationship of type "Folder Hierarchy" Ideally, in plain Oracle SQL, it would be easy to use CONNECT BY clause. But with Hibernate, some reason it ends up with Double "LEFT OUTER JOIN" Parent to Child and Child to Parent.

Problem: When hibernate pulls Object of "Dashboard" Folder are retrieved in "Cartersian product" Meaning, it does pulls out parent/child, but then it also attaches same child folders to Dashboard!.

Here is more information, I have ONLY typed relationships into following code fragment. Tables:

DASHBOARD {
  ID INTEGER PRIMARY KEY,
  NAME VARCHAR2(100) ...
}
FOLDER {
  ID INTEGER PRIMARY KEY,
  DASHBOARD_ID INTEGER,
  NAME VARCHAR2(100),
  PARENT_FOLDER_ID INTEGER .....
}

public class DashBoard{
    ....
    ....

@OneToMany(mappedBy = "dashboard", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@OrderBy("NAME ASC")
@Sort(type = SortType.NATURAL)
public SortedSet<Folder> getFolders() {
    return folders;
}    

}

public class Folder{
....
....
    @ManyToOne(fetch = FetchType.EAGER, optional = false, cascade = CascadeType.ALL)
@JoinColumn(name = "DASHBOARD_ID", nullable = false)
public DashBoard getDashBoard() {
    return dashboard;
}

@OneToMany(mappedBy = "parent", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@OrderBy("NAME ASC")
@Sort(type = SortType.NATURAL)
public SortedSet<Folder> getChildFolders() {
    return folders;
}             

@ManyToOne(fetch = FetchType.EAGER, optional = true, cascade = CascadeType.ALL)
@JoinColumn(name = "PARENT_FOLDER_ID")
public Criterion getParent() {
    return parent;
}
}
有帮助吗?

解决方案

I have dropped the relationship DashBoard --> Folder, and maintain it manually by DAO layer. This solves hibernate cartisian join issue. I would still think that there might be better solution than this, please let me know.

Thanks,

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top