Hibernate 查询的问题?

xiao_HEIx 2014-04-14 02:08:16
/**
* 多条件模糊分页查询总数量
* */
public int searchTotal(SupplierParam supplierParam) {
StringBuilder hql = new StringBuilder(
"select count(*) from Supplier s inner join fetch s.types t where 1=1 ");
Supplier supplier = supplierParam.getSupplier();
if(supplier.getSupplier_name()!=null && !supplier.getSupplier_name().equalsIgnoreCase("")){
hql.append(" and s.supplier_name like '%"+supplier.getSupplier_name()+"%'");
}
if(supplier.getSupplier_person()!=null && !supplier.getSupplier_person().equalsIgnoreCase("")){
hql.append(" and s.supplier_person like '%"+supplier.getSupplier_person()+"%'");
}
if(supplier.getSupplier_address()!=null && !supplier.getSupplier_address().equals("")){
hql.append(" and s.supplier_address like '%"+supplier.getSupplier_address()+"%'");
}
if(supplierParam.getSupplier_outIn()!=null && !supplierParam.getSupplier_outIn().equals("")){
hql.append(" and s.supplier_isInner = "+supplierParam.getSupplier_outIn());
}
if(supplierParam.getTypeID()!=null && !supplierParam.getTypeID().equals("")){
hql.append(" and t.id = '"+supplierParam.getTypeID()+"'");
}
System.out.println("hql = " + hql.toString());
Integer total = Integer.parseInt(hibernateTemplate.find(hql.toString())
.listIterator().next().toString());
return total.intValue();
}

错误:


求各位大神解答
...全文
117 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hehewjt 2014-04-14
  • 打赏
  • 举报
回复
遇见这种问题,你可以先把sql打印出来,在sql控制台执行看有问题没有,如果没问题的话再查看hiberante的问题
huwenhu2007 2014-04-14
  • 打赏
  • 举报
回复
抱歉,上面的说错了,fetch的作用是立刻抓取的意思,就是在已经设置为延迟加载的对象那里添加fetch后,该对象会变为非延迟加载,作用和lazy=false一样的
huwenhu2007 2014-04-14
  • 打赏
  • 举报
回复
你的 s.types是不是设置的lazy=false,如果是就去掉fetch,fetch的作用和lazy=true是一样的,表示使用延迟加载
java_liyi 2014-04-14
  • 打赏
  • 举报
回复
从提示上看,应该是inner join fetch的对象s.types的fetch定义有问题 找了篇文章 http://blog.csdn.net/maggiehexu/article/details/7491043 看看有帮助么
小律律 2014-04-14
  • 打赏
  • 举报
回复
查询语言有错。 查询语句里面 join on 语句。看一下
小帅庾 2014-04-14
  • 打赏
  • 举报
回复
select count(*) from Supplier s inner join fetch s.types t where 1=1  这个 join ****on** 你这里是不是少了一个on的连接条件啊?

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧