hql报错--HibernateQueryException

错误信息

com.smart.base.exception.SqlException: com.smart.base.exception.SqlException: org.springframework.orm.hibernate3.HibernateQueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=f,role=com.smart.comm.entity.QtBaseEntity.flights,tableName=t_qt_flight,tableAlias=flights1_,origin=t_qt_base qtbaseenti0_,columns={qtbaseenti0_.id ,className=com.smart.comm.entity.QtFlightEntity}}] [select count(*) from com.smart.comm.entity.QtBaseEntity qb left join fetch qb.flights f left join fetch qb.orders o where 1=1 and qb.mno=? ]; nested exception is org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=f,role=com.smart.comm.entity.QtBaseEntity.flights,tableName=t_qt_flight,tableAlias=flights1_,origin=t_qt_base qtbaseenti0_,columns={qtbaseenti0_.id ,className=com.smart.comm.entity.QtFlightEntity}}] [select count(*) from com.smart.comm.entity.QtBaseEntity qb left join fetch qb.flights f left join fetch qb.orders o where 1=1 and qb.mno=? ]
    at com.smart.framework.base.BaseDAO.find(BaseDAO.java:869)
    at com.smart.oo.dao.imp.QtBaseDaoImpl.queryByPage(QtBaseDaoImpl.java:46)
    at com.smart.oo.service.imp.QtBaseServiceImpl.queryByPage(QtBaseServiceImpl.java:22)
    at com.smart.oo.service.imp.QtBaseServiceImpl$$FastClassByCGLIB$$477a7f0a.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
…………
关键错误信息
[select count(*) from com.smart.comm.entity.QtBaseEntity qb left join fetch qb.flights f left join fetch qb.orders o where 1=1 and qb.mno=? ]
错误原因

在hql查询语句中,如果使用select count(*)查询,后面就不能接fetch

解决办法

fetch去掉
分页查询时,在查询数量的方法中使用String.replaceAll("fetch", ""); 替换fetch

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值