我有以下查询,我使用hibernate一个JPA提供程序:
entityManager().createQuery(
"SELECT page FROM ProjectPage page"
+" left join fetch page.categorySet as category"
+ " where page.id = :id "
+ " and category.parentCategory is null "
+ " and (category.status is null or category.status != :status_val) "
,ProjectPage.class).setParameter("id", id).setParameter("status_val", Status.DELETED).getSingleResult();
以下分别是ProjectPage
和Category
的实体:
@Entity
@Table(name="project_page")
@Configurable
public class ProjectPage {
@OneToMany( mappedBy = "parentPage")
private Set<Category> categorySet = new HashSet<Category>();
}
@Configurable
@Table(name="category")
@Entity
public class Category{
@OneToMany(cascade = CascadeType.ALL, mappedBy = "parentCategory",fetch=FetchType.EAGER)
private Set<com.se.dataadminbl.model.Category> categorySet = new HashSet<com.se.dataadminbl.model.Category>();
}
在上面的查询中,我试图获取一个ProjectPage
和它的categorySet
,如上面所示,类Category
包含它的一组类型,所以每个ProjectPage
对象都将包含一组Category
,而这个集合中的每个对象都将包含一组Category
,现在的问题是,当我检索ProjectPage
对象时,where子句中的条件仅应用于每个Category
中的第一级集合,而不是在每个Category
中的每个集合上,因此我想要进行一个递归查询,以便我可以将where条件应用到nth级别,而不是使用代码,我试过使用拦截器,但不起作用,知道怎么做吗?
发布于 2015-01-15 21:50:11
https://stackoverflow.com/questions/27970474
复制相似问题