关于 HQL语句迫切左外联 和 getHibernateTemplate().find();的疑问
publicList<Goods>search(Goodscondition){Stringhql="FromGoodsgleftjoinfetchg.usersByBu...
public List<Goods> search(Goods condition) {
String hql = "From Goods g left join fetch g.usersByBuyerId b ";
if (condition != null) {
if (condition.getUsersByBuyerId()!= null
&& !"".equals(condition.getUsersByBuyerId().getUserName())) {
hql += "left join fetch g.bids C";
}
}
List<Goods> ret = (List<Goods>)super.getHibernateTemplate().find(hql);
return ret;
/*Session session = super.getSession();
Query query = session.createQuery(hql);
return query.list();*/
}
HQL 用了迫切左外联 应该优先级比FETECH 和LAZY高 为什么他还报我
LazyInitializationException
而用注释掉的那部分代码就不用设置LAZY 不会报错这是为什么,
List<Goods> ret = (List<Goods>)super.getHibernateTemplate().find(hql);
return ret;
/*Session session = super.getSession();
Query query = session.createQuery(hql);
return query.list();*/
这两段代码不是一样的嘛~? 展开
String hql = "From Goods g left join fetch g.usersByBuyerId b ";
if (condition != null) {
if (condition.getUsersByBuyerId()!= null
&& !"".equals(condition.getUsersByBuyerId().getUserName())) {
hql += "left join fetch g.bids C";
}
}
List<Goods> ret = (List<Goods>)super.getHibernateTemplate().find(hql);
return ret;
/*Session session = super.getSession();
Query query = session.createQuery(hql);
return query.list();*/
}
HQL 用了迫切左外联 应该优先级比FETECH 和LAZY高 为什么他还报我
LazyInitializationException
而用注释掉的那部分代码就不用设置LAZY 不会报错这是为什么,
List<Goods> ret = (List<Goods>)super.getHibernateTemplate().find(hql);
return ret;
/*Session session = super.getSession();
Query query = session.createQuery(hql);
return query.list();*/
这两段代码不是一样的嘛~? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询