日期:2014-05-18  浏览次数:20830 次

请问hibernate怎么对List属性进行搜索呢?
目前要根据商品属性搜索出商品,要怎么写呢?


public class Product  {
private ProductType productType;// 商品类型
}


public class ProductType  {
private String name;// 类型名称
private List<ProductAttribute> productAttributeList;// 商品属性
}

public class ProductAttribute  {
private String name;// 属性名称
}



//搜索
public List<Product> getProductList() {
 
DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Product.class);
 
detachedCriteria.createAlias("productType", "productType");
detachedCriteria.add(Restrictions.like("productType.name", "%手机%"));//这样可以搜索出类型名称

这边要搜索商品属性要怎么写呢?
detachedCriteria.add(Restrictions.like("productType.productAttributeList.name", "%500万像素%"));

}

------解决方案--------------------
说实话DetachedCriteria 这个玩意很少用,我看你还是写hql语言吧。。。灵活。。。