开发者

Hibernate Exception : Illegal attempt to dereference a collection

开发者 https://www.devze.com 2023-03-12 17:10 出处:网络
Consider the following Entities. public class Product{ int id; Date effectiveDate; Date expiryDate; Set<Inventory> productInventories;

Consider the following Entities.

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;
}

The above two entities maps to tables Product and Inventory respectively.

Now I have to retrieve Products based on certain conditions in Product entity as well as Inventory entity.

For ex the conditi开发者_开发技巧ons are given travel start date and travel end date has to suit effective and expiry date of Product. Product Inventory should have availableQuantity > 0.

To do this how can i write the hql. Can i write something like the following

Query query = session.createQuery("from Product As product " +
                          "where product.effectiveDate <= :travelStartDate "+
                          "AND product.expiryDate >= :travelEndDate " +
                          "AND product.productInventories.availableQuantity >0 ");

When i execute the above query, it throws a Illegal attempt to dereference a collection exception.


You probably want something like

from Product as product 
    inner join product.productInventories inv with inv.availableQuantity>0 

See http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html#queryhql-joins

0

精彩评论

暂无评论...
验证码 换一张
取 消