请考虑以下实体.
public class Product{
int id;
Date effectiveDate;
Date expiryDate;
Set<Inventory> productInventories;
}
public class Inventory{
int invId;
Date inventoryDate;
boolean soldOut;
int availableQuantity;
Product product;
}
Run Code Online (Sandbox Code Playgroud)
以上两个实体分别映射到表Product和Inventory.
现在我必须根据Product实体和Inventory实体中的某些条件检索产品.
对于前提条件,旅行开始日期和旅行结束日期必须符合产品的有效期限和到期日期.产品库存应该有可用数量> 0.
要做到这一点,我怎么能写hql.我可以写下面的内容吗?
Query query = session.createQuery("from Product As product " +
"where product.effectiveDate <= :travelStartDate "+
"AND product.expiryDate >= :travelEndDate " +
"AND product.productInventories.availableQuantity >0 ");
Run Code Online (Sandbox Code Playgroud)
当我执行上面的查询时,它会抛出非法尝试取消引用集合异常.
你可能想要这样的东西
from Product as product
inner join product.productInventories inv with inv.availableQuantity>0
Run Code Online (Sandbox Code Playgroud)
见http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html#queryhql-joins
| 归档时间: |
|
| 查看次数: |
10588 次 |
| 最近记录: |