Hibernate中HQL查询语句的问题,请各位帮忙!

[复制链接]
查看11 | 回复3 | 2007-10-10 09:16:41 | 显示全部楼层 |阅读模式
偶刚开始学习hibernate,在学习一个生成树的例子时总是搞不明白执行下面这个语句后list中的值是什么,请各位指教,谢谢!
list = session.createQuery("from ProductCategory p left join fetch p.parentCategory&quot

.list();
关于上句使用到的表如下:
ProductCategory中的字段(因发贴时多个空格不显示,为各位查看方便,我使用“---”代替空格,请知晓~~):
CategoryID-----ParentCategoryID-----CategoryName
1------------------------NULL-------------------------家居
2 -----------------------NULL-------------------------图书
3 ---------------------------1 ----------------------------厨具
4 ---------------------------1------------------------ 床上用品
5 ---------------------------2-----------------------计算机类图书
6----------------------------2 ---------------------------小说








ProductCategory.java类的语句如下:
public class ProductCategory implements java.io.Serializable {

private Integer categoryId;

private String categoryName;

private ProductCategory parentCategory;

private Set subCategories = new HashSet(0);

private Set products = new HashSet(0);

public Set getProducts()
{

return products;

}

public void setProducts(Set products)
{

this.products = products;

}

public ProductCategory()
{

}

public Integer getCategoryId()
{

return this.categoryId;

}

public void setCategoryId(Integer categoryId)
{

this.categoryId = categoryId;

}

public String getCategoryName()
{

return this.categoryName;

}

public void setCategoryName(String categoryName)
{

this.categoryName = categoryName;

}

public ProductCategory getParentCategory()
{

return parentCategory;

}

public void setParentCategory(ProductCategory parentCategory)
{

this.parentCategory = parentCategory;

}

public Set getSubCategories()
{

return subCategories;

}

public void setSubCategories(Set subCategories)
{

this.subCategories = subCategories;

}
}

请各位大侠指教,非常感谢!如还有什么未写清楚的请回帖询问,谢谢!!!!
回复

使用道具 举报

千问 | 2007-10-10 09:16:41 | 显示全部楼层
list 中是ProductCategory对象 而且其中的parentCategory对象是关联select出来的,不象hibernate中缺省的lazy装载
回复

使用道具 举报

千问 | 2007-10-10 09:16:41 | 显示全部楼层
我用myeclipse中的HQL查询,发现查询结果是一组对象.
对于Lazy装载,我还不太明白,谷歌一下吧~
多谢版主~
回复

使用道具 举报

千问 | 2007-10-10 09:16:41 | 显示全部楼层
学习了。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行