我在使用eclipselink2.5进行JPQL级联查询时出现问题
请参阅代码
public class Category{
...
@JoinColumn(name = "parent_category", referencedColumnName = "id")
@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER,optional = true)
private Category parentCategory;
...
}
String jpql = "select o from Category o order by o.parentCategory.sort ASC";
问题是,如果'o.parentCategory'为空,则JPQL返回列表不包括'o'。
请参阅此表http://i.stack.imgur.com/xsXvk.jpg
the return list only rows id is 2,3,4 .
because the column parent_category is null, I lost rows 1,5,6
the correct result should be return all rows
Looking forward to your help!
答案 0 :(得分:0)
在order by子句中使用o.parentCategory.sort强制使用过滤空值的内部联接。如果要包含空值,则需要在查询中使用显式外连接:
"select o from Category o outer join o.parentCategory parentCategory order by parentCategory.sort ASC"