本文介绍了QuerySyntaxException:无法找到类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用hql生成类JunctionManagementListDto的实际Java对象.但是我最终在控制台上遇到了以下异常
I am using hql to generate an actual Java object of class JunctionManagementListDto. But I end up with the following exception on my console
org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate class [JunctionManagementListDto] [SELECT new JunctionManagementListDto(c.siteId, c.name, c.ip, c.customer.id, zm.zone.name) FROM com.traff.hibernate.model.Controllers c, com.traff.hibernate.model.ZoneControllerMapping zm WHERE c.siteId = zm.controller.siteId ]
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:79)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:255)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1735)
at com.traff.hibernate.generic.GenericDAOImpl.readListByHql(GenericDAOImpl.java:107)
at com.traff.hibernate.daoImpl.JnMgmtLogDaoImpl.getJunctionManagementList(JnMgmtLogDaoImpl.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy175.getJunctionManagementList(Unknown Source)
at com.traff.service.report.JunctionManagementReportService.prepareStatusList(JunctionManagementReportService.java:37)
at com.traff.service.report.JunctionManagementReportService$$FastClassBySpringCGLIB$$472093e1.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717)
......
我的hql查询是在JnMgmtLogDaoImpl类中编写的,所有必需的导入为
My hql query is written inside JnMgmtLogDaoImpl class with all necessary imports as
public List<JunctionManagementListDto> getJunctionManagementList(String zoneName, Integer customerId) {
String hql = "SELECT new JunctionManagementListDto(c.siteId, c.name, c.ip, c.customer.id, zm.zone.name) "
+"FROM Controllers c, ZoneControllerMapping zm "
+"WHERE c.siteId = zm.controller.siteId ";
if(zoneName != "")
hql += " and zm.zone.name='"+zoneName+"' ";
if (customerId!=null)
hql += " and zm.controller.customer.id='"+customerId+"' ";
return super.readListByHql(hql);
}
和JunctionManagementListDto声明为
and JunctionManagementListDto is declared as
公共类JunctionManagementListDto {
public class JunctionManagementListDto {
private String zoneName;
private Integer siteId;
private String name;
private String ip;
private Integer customerId;
public String getZoneName() {
return zoneName;
}
public void setZoneName(String zoneName) {
this.zoneName = zoneName;
}
public Integer getSiteId() {
return siteId;
}
public void setSiteId(Integer siteId) {
this.siteId = siteId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public Integer getCustomerName() {
return customerId;
}
public void setCustomerName(Integer customerId) {
this.customerId = customerId;
}
public JunctionManagementListDto(Integer siteId, String zoneName, String ip, Integer customerId, String junctionName) {
super();
this.siteId = siteId;
this.customerId = customerId;
this.ip = ip;
this.zoneName = zoneName;
name = junctionName;
}
public JunctionManagementListDto(){
}
}
是什么导致此异常,我该如何解决?
What is causing this exception and how can I solve it?
推荐答案
我通过指定构造函数的全限定名称解决了此问题.
I resolved this issue by specifying the fully qualified name of the constructor.
public List<JunctionManagementListDto> getJunctionManagementList(String zoneName, Integer customerId) {
String hql = "SELECT new (packagename).JunctionManagementListDto(c.siteId, c.name, c.ip, c.customer.id, zm.zone.name) "
+"FROM Controllers c, ZoneControllerMapping zm "
+"WHERE c.siteId = zm.controller.siteId ";
if(zoneName != "")
hql += " and zm.zone.name='"+zoneName+"' ";
if (customerId!=null)
hql += " and zm.controller.customer.id='"+customerId+"' ";
return super.readListByHql(hql);
}
这篇关于QuerySyntaxException:无法找到类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!