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