【发布时间】:2013-11-06 08:59:03
【问题描述】:
我有三张表,一张是 ItemCategory、ItemMaster 和 Price。我在 ItemMaster 表中引用 itemaCategoryId,并且在价格中引用 itemmasterid。现在我必须按 itemcategory id 显示价格订单的内容。这是我的条件查询。
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Price> cq = cb.createQuery(Price.class);
Root<Price> root = cq.from(Price.class);
Root<ItemMaster> itemMasterRoot = cq.from(ItemMaster.class);
Root<ItemCategory> itemCategoryRoot = cq.from(ItemCategory.class);
Join<ItemMaster, ItemCategory> s=itemMasterRoot.join(ItemMaster_.category);
Join<Price,ItemMaster> y=root.join(Price_.itemMaster);
Path<Long> itemMasterId=root.get(Price_.itemMasterId);
cq.select(root).where(cb.equal(root.get(Price_.priceMasterId), priceMasterId))
.orderBy(cb.asc(itemMasterId));
TypedQuery<Price> q = entityManager.createQuery(cq);
高于我的标准查询
【问题讨论】:
-
为什么在 Price 中有 itemMasterId 和 itemMaster 属性?它们的意思是一样的吗?
-
没有。仅参考 itemmasterid 的价格表。我必须按 itemcategoryid 显示价格表和订单的内容,这是我需要的。但不知道如何正确加入标准。
标签: jpa criteria criteria-api