java hibernate 报错 org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate class

用Spring boot 写表连接查询的时候一直报错 Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate class [CommonBuyingVO]   

commonBuyingVO是我自己写的一个虚类,用来接收两个表的数据,在这个类中也写了全参构造报错的内容为:

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate class [CommonBuyingVO] [select new CommonBuyingVO(c.comId,c.merchantIds,c.comName,c.comOutMoney,c.comNowMoney,c.comStock,c.com_salesVolume,c.comType,c.comClass,c.comStatus,c.comimgPath,c.comUrl,c.comSort,c.comValidData,c.comAddDate,c.comUpDate,c.comDepict,s.scaBeginDate,s.scaEndDate) from com.example.demo.entity.CommonBuying c ,com.example.demo.entity.ScareBuying s where c.comId=s.proid and c.comType = ?1 and c.comStatus!=?2 and c.merchantIds=?3 ]
	at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:74) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
	at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:91) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:268) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:190) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
	at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
	at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:76) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
	at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:150) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
	at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:302) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
	at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:240) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
	at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1894) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
	at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:291) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
	... 49 common frames omitted

我的查询语句:

@Query("select new CommonBuyingVO(c.comId,c.merchantIds,c.comName,c.comOutMoney,c.comNowMoney,c.comStock,"+ 
			"c.com_salesVolume,c.comType,c.comClass,c.comStatus,c.comimgPath," + 
			"c.comUrl,c.comSort,c.comValidData,c.comAddDate,c.comUpDate,c.comDepict," + 
			"s.scaBeginDate,s.scaEndDate) from CommonBuying c ,ScareBuying s where c.comId=s.proid and c.comType = ?1 and c.comStatus!=?2 and c.merchantIds=?3 ")
	List<CommonBuyingVO> getScareBuying(String comType,String comStatus,String merchantIds);

解决方法:

@Query("select new com.example.demo.entity.CommonBuyingVO(c.comId,c.merchantIds,c.comName,c.comOutMoney,c.comNowMoney,c.comStock,"+ 
			"c.com_salesVolume,c.comType,c.comClass,c.comStatus,c.comimgPath," + 
			"c.comUrl,c.comSort,c.comValidData,c.comAddDate,c.comUpDate,c.comDepict," + 
			"s.scaBeginDate,s.scaEndDate) from CommonBuying c ,ScareBuying s where c.comId=s.proid and c.comType = ?1 and c.comStatus!=?2 and c.merchantIds=?3 ")
	List<CommonBuyingVO> getScareBuying(String comType,String comStatus,String merchantIds);
在虚类前面指定包的路径,这样写后,就不报错了






  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值