hibernate如何连接两张表查询,对拼接sql语句有什么要求

qq_35973430 2016-09-14 10:15:37
2016-09-14 10:10:57,679 DEBUG [http-8080-2] - Bypassing /buildingStandNews/list_getStand
2016-09-14 10:10:57,681 DEBUG [http-8080-2] - Validating /buildingStandNews/list_getStand with method toList.
2016-09-14 10:10:57,681 [http-8080-2] INFO com.slj.sys.aop.SpringBeanAspect - 开始业务处理[getAccess];全路径[com.slj.sys.biz.impl.AdminBizImpl.getAccess]
2016-09-14 10:10:58,220 [http-8080-2] INFO com.slj.sys.aop.SpringBeanAspect - 结束业务处理[getAccess];耗时:539毫秒;全路径[com.slj.sys.biz.impl.AdminBizImpl.getAccess]
getInfoTree DAO==========》[com.slj.info.po.BuildingStandClass@1dce158, com.slj.info.po.BuildingStandClass@4e96e9, com.slj.info.po.BuildingStandClass@195a569]
===================hql===================>>>>>>>>>>>>>>>from BuildingStandNews po where 1=1 c.sup_class_Id = :classId ) and status = :status order by po.createdTime desc
========================hqlcount==========================>>>>>>>>>>>>>>>select count(po.newsId) from BuildingStandNews po where 1=1 c.sup_class_Id = :classId ) and status = :status
===================hql===================>>>>>>>>>>>>>>>from BuildingStandNews po where po.classId in (select c.class_Id from Building_Stand_Class c where c.sup_class_Id = :classId ) and status = :status order by po.createdTime desc
========================hqlcount==========================>>>>>>>>>>>>>>>select count(po.newsId) from BuildingStandNews po where po.classId in (select c.class_Id from Building_Stand_Class c where c.sup_class_Id = :classId ) and status = :status
2016-09-14 10:10:58,233 [http-8080-2] ERROR com.slj.info.hibernate.impl.BuildingStandNewsDAOImpl - 根据指定的带参数名和参数值的SQL/HQL更新据库操作失败org.springframework.orm.hibernate3.HibernateQueryException: Building_Stand_Class is not mapped [select count(po.newsId) from com.slj.info.po.BuildingStandNews po where po.classId in (select c.class_Id from Building_Stand_Class c where c.sup_class_Id = :classId ) and status = :status]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: Building_Stand_Class is not mapped [select count(po.newsId) from com.slj.info.po.BuildingStandNews po where po.classId in (select c.class_Id from Building_Stand_Class c where c.sup_class_Id = :classId ) and status = :status]
2016-09-14 10:10:58,233 [http-8080-2] ERROR com.slj.biz.info.manager.impl.BuildingStandNewsBizImpl - 获取标准列表数据库操作失败com.slj.orm.util.DAOException:
非常遗憾的通知您,程序发生了异常.
根据指定的带参数名和参数值的SQL/HQL更新据库操作失败org.springframework.orm.hibernate3.HibernateQueryException: Building_Stand_Class is not mapped [select count(po.newsId) from com.slj.info.po.BuildingStandNews po where po.classId in (select c.class_Id from Building_Stand_Class c where c.sup_class_Id = :classId ) and status = :status]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: Building_Stand_Class is not mapped [select count(po.newsId) from com.slj.info.po.BuildingStandNews po where po.classId in (select c.class_Id from Building_Stand_Class c where c.sup_class_Id = :classId ) and status = :status]
2016-09-14 10:10:58,233 [http-8080-2] ERROR com.slj.info.action.BuildingStandNewsAction - 获取建筑标准信息列表失败com.slj.biz.util.BizException:
非常遗憾的通知您,程序发生了异常.
获取标准列表数据库操作失败com.slj.orm.util.DAOException:
非常遗憾的通知您,程序发生了异常.
根据指定的带参数名和参数值的SQL/HQL更新据库操作失败org.springframework.orm.hibernate3.HibernateQueryException: Building_Stand_Class is not mapped [select count(po.newsId) from com.slj.info.po.BuildingStandNews po where po.classId in (select c.class_Id from Building_Stand_Class c where c.sup_class_Id = :classId ) and status = :status]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: Building_Stand_Class is not mapped [select count(po.newsId) from com.slj.info.po.BuildingStandNews po where po.classId in (select c.class_Id from Building_Stand_Class c where c.sup_class_Id = :classId ) and status = :status]
2016-09-14 10:10:58,234 DEBUG [http-8080-2] - Forwarding to location /message.jsp
2016-09-14 10:10:58,238 [http-8080-2] INFO com.slj.sys.interceptor.MonitorInterceptor - 18ms,调用方法:null,actionName:com.slj.info.action.BuildingStandNewsAction@11bc26f
2016-09-14 10:10:58,238 [http-8080-2] INFO com.slj.sys.interceptor.MonitorInterceptor - 付云[fuyun]调用了Action方法[方法:toList,参数action值:null];请求路径[/AdminModule/buildingStandNews/list_getStand.action]
2016-09-14 10:10:58,239 [http-8080-2] INFO com.slj.sys.aop.SpringBeanAspect - 开始业务处理[save];全路径[com.slj.sys.biz.impl.EventBizImpl.save]
2016-09-14 10:10:58,239 DEBUG [http-8080-2] - BeanUtils.populate(com.slj.sys.po.EventPO@b165bd, {staffId=361, description=付云[fuyun]调用了Action方法[方法:toList,参数action值:null], requestPath=/AdminModule/buildingStandNews/list_getStand.action, staffName=付云, account=fuyun, methodName=方法:toList,参数action值:null, costTime=18})
2016-09-14 10:10:58,239 DEBUG [http-8080-2] - Converting 'BigDecimal' value '361' to type 'String'
2016-09-14 10:10:58,239 DEBUG [http-8080-2] - Convert string '付云[fuyun]调用了Action方法[方法:toList,参数action值:null]' to class 'java.lang.String'
2016-09-14 10:10:58,239 DEBUG [http-8080-2] - Converting 'String' value '付云[fuyun]调用了Action方法[方法:toList,参数action值:null]' to type 'String'
2016-09-14 10:10:58,239 DEBUG [http-8080-2] - Convert string '/AdminModule/buildingStandNews/list_getStand.action' to class 'java.lang.String'
2016-09-14 10:10:58,239 DEBUG [http-8080-2] - Converting 'String' value '/AdminModule/buildingStandNews/list_getStand.action' to type 'String'
2016-09-14 10:10:58,239 DEBUG [http-8080-2] - Convert string '付云' to class 'java.lang.String'
2016-09-14 10:10:58,239 DEBUG [http-8080-2] - Converting 'String' value '付云' to type 'String'
2016-09-14 10:10:58,239 DEBUG [http-8080-2] - Convert string 'fuyun' to class 'java.lang.String'
2016-09-14 10:10:58,239 DEBUG [http-8080-2] - Converting 'String' value 'fuyun' to type 'String'
2016-09-14 10:10:58,239 DEBUG [http-8080-2] - Convert string '方法:toList,参数action值:null' to class 'java.lang.String'
2016-09-14 10:10:58,239 DEBUG [http-8080-2] - Converting 'String' value '方法:toList,参数action值:null' to type 'String'
2016-09-14 10:10:58,239 DEBUG [http-8080-2] - Converting 'BigDecimal' value '18' to type 'BigDecimal'
2016-09-14 10:10:58,239 DEBUG [http-8080-2] - No conversion required, value is already a BigDecimal
2016-09-14 10:10:58,241 [http-8080-2] DEBUG com.slj.sys.dao.impl.EventDAOImpl - save entity: com.slj.sys.po.EventPO@b165bd
2016-09-14 10:10:58,241 [http-8080-2] INFO com.slj.sys.aop.SpringBeanAspect - 结束业务处理[save];耗时:2毫秒;全路径[com.slj.sys.biz.impl.EventBizImpl.save]
...全文
512 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_35973430 2016-09-23
  • 打赏
  • 举报
回复
select * from 表一 a where a.classid in (select classid from 表二 b where b.supclassid ='从前台传过来的参数' )
意思是:点击二级分类会把属于二级分类下的所有三级分类相关的咨询展现
公司已经对前台传来的参数封装过了:


  • 打赏
  • 举报
回复
楼主你是否可以贴出来你的sql代码,两表链接这简单的,只要会写sql语句的人都知道的。
xiangfe 2016-09-14
  • 打赏
  • 举报
回复
hibernate不需要我们去管SQL如何书写的问题,连接查询,在相应的bean.xml文件中配置一对多,多对一关联映射就可以了
lao_niu_wu_yu 2016-09-14
  • 打赏
  • 举报
回复
where 1=1 c.sup_class_Id = :classId,能把sql贴全吗,标准sql的where条件都得用and连接,hibernate解析出来的sql也得符合这个原则吧?hibernate不是很熟

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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