错误信息
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