问题描述
报错:org.hibernate.hql.ast.QuerySyntaxException:Unabletolocateappropriateconstructoronclass代码是Queryquery=session.createQuery("selectBuyPlanning(t.id,t.pcode,t.pdatd,t.entryusername,t.bossdatd,t.recordlock,t.recordstatus,t.recordshow,t.departmentcode,t.enterprisecode)fromBuyPlanningast,ErpSystemCheckingasvwheret.pcode=v.pcodeandv.numid="+String.valueOf(numid));其中BuyPlanning和ErpSystemChecking都是通过myeclipse直接对数据表做的“HibernateReverseEngineering”获得的publicclassBuyPlanningextendsAbstractBuyPlanningimplementsjava.io.Serializable{//Constructors/**defaultconstructor*/publicBuyPlanning(){}/**minimalconstructor*/publicBuyPlanning(Integerid){super(id);}/**fullconstructor*/publicBuyPlanning(Integerid,Stringpcode,Timestamppdatd,Stringentryusername,Timestampbossdatd,Stringrecordlock,Stringrecordstatus,Stringrecordshow,Stringdepartmentcode,Stringenterprisecode){super(id,pcode,pdatd,entryusername,bossdatd,recordlock,recordstatus,recordshow,departmentcode,enterprisecode);}}publicabstractclassAbstractBuyPlanningimplementsjava.io.Serializable{//FieldsprivateIntegerid;privateStringpcode;privateTimestamppdatd;privateStringentryusername;privateTimestampbossdatd;privateStringrecordlock;privateStringrecordstatus;privateStringrecordshow;privateStringdepartmentcode;privateStringenterprisecode;//Constructors/**defaultconstructor*/publicAbstractBuyPlanning(){}/**minimalconstructor*/publicAbstractBuyPlanning(Integerid){this.id=id;}/**fullconstructor*/publicAbstractBuyPlanning(Integerid,Stringpcode,Timestamppdatd,Stringentryusername,Timestampbossdatd,Stringrecordlock,Stringrecordstatus,Stringrecordshow,Stringdepartmentcode,Stringenterprisecode){this.id=id;this.pcode=pcode;this.pdatd=pdatd;this.entryusername=entryusername;this.bossdatd=bossdatd;this.recordlock=recordlock;this.recordstatus=recordstatus;this.recordshow=recordshow;this.departmentcode=departmentcode;this.enterprisecode=enterprisecode;}//PropertyaccessorspublicIntegergetId(){returnthis.id;}publicvoidsetId(Integerid){this.id=id;}publicStringgetPcode(){returnthis.pcode;}publicvoidsetPcode(Stringpcode){this.pcode=pcode;}publicTimestampgetPdatd(){returnthis.pdatd;}publicvoidsetPdatd(Timestamppdatd){this.pdatd=pdatd;}publicStringgetEntryusername(){returnthis.entryusername;}publicvoidsetEntryusername(Stringentryusername){this.entryusername=entryusername;}publicTimestampgetBossdatd(){returnthis.bossdatd;}publicvoidsetBossdatd(Timestampbossdatd){this.bossdatd=bossdatd;}publicStringgetRecordlock(){returnthis.recordlock;}publicvoidsetRecordlock(Stringrecordlock){this.recordlock=recordlock;}publicStringgetRecordstatus(){returnthis.recordstatus;}publicvoidsetRecordstatus(Stringrecordstatus){this.recordstatus=recordstatus;}publicStringgetRecordshow(){returnthis.recordshow;}publicvoidsetRecordshow(Stringrecordshow){this.recordshow=recordshow;}publicStringgetDepartmentcode(){returnthis.departmentcode;}publicvoidsetDepartmentcode(Stringdepartmentcode){this.departmentcode=departmentcode;}publicStringgetEnterprisecode(){returnthis.enterprisecode;}publicvoidsetEnterprisecode(Stringenterprisecode){this.enterprisecode=enterprisecode;}}
解决方案
解决方案二:
org.hibernate.hql.ast.QuerySyntaxException:Unabletolocateappropriateconstructoronclass要重点检查全参数构造器的参数类型是否正确了,这是最常发生的问题。
解决方案三:
org.hibernate.hql.ast.QuerySyntaxException:Unabletolocateappropriateconstructoronclass找不到合适的构造方法。selectBuyPlanning(t.id,t.pcode,t.pdatd,t.entryusername,t.bossdatd,t.recordlock,t.recordstatus,t.recordshow,t.departmentcode,t.enterprisecode)查看一下构成BuyPlanning这个对象的构造方法的参数个数、参数类型与上面这个hql语句中查询的字段个数、字段类型是否都匹配。扫了一眼,好像参数个数是一样的,看是不是字段类型与参数类型不一致导致的。
解决方案四:
你的HQL没有写对啊Queryquery=session.createQuery("selectBuyPlanning(t.id,t.pcode,t.pdatd,t.entryusername,t.bossdatd,t.recordlock,t.recordstatus,t.recordshow,t.departmentcode,t.enterprisecode)fromBuyPlanningast,ErpSystemCheckingasvwheret.pcode=v.pcodeandv.numid="+String.valueOf(numid));改为Queryquery=session.createQuery("selectnewBuyPlanning(t.id,t.pcode,t.pdatd,t.entryusername,t.bossdatd,t.recordlock,t.recordstatus,t.recordshow,t.departmentcode,t.enterprisecode)fromBuyPlanningast,ErpSystemCheckingasvwheret.pcode=v.pcodeandv.numid="+String.valueOf(numid));少了一个“new”
解决方案五:
你的fullconstructor和minimalconstructor检查这两个构造函数的数据类型和你配置文件里定义的是否匹配。下面的链接供你参考。
解决方案六:
我发帖发错了,是有那个new的引用3楼的回复:
你的HQL没有写对啊Queryquery=session.createQuery("selectBuyPlanning(t.id,t.pcode,t.pdatd,t.entryusername,t.bossdatd,t.recordlock,t.recordstatus,t.recordshow,t.departmentcode,t.enterprisecode)fromBuyPla……
解决方案七:
数据库的数据是[id][int]IDENTITY(1,1)NOTNULL,[pcode][nvarchar](50)COLLATEChinese_PRC_CI_ASNULL,[pdatd][datetime]NULL,[entryusername][nvarchar](20)COLLATEChinese_PRC_CI_ASNULL,[bossdatd][datetime]NULL,[recordlock][nvarchar](1)COLLATEChinese_PRC_CI_ASNULL,[recordstatus][nvarchar](1)COLLATEChinese_PRC_CI_ASNULL,[recordshow][nvarchar](1)COLLATEChinese_PRC_CI_ASNULL,[departmentcode][nvarchar](50)COLLATEChinese_PRC_CI_ASNULL,[enterprisecode][nvarchar](50)COLLATEChinese_PRC_CI_ASNULL析构函数的数据是privateIntegerid;privateStringpcode;privateTimestamppdatd;privateStringentryusername;privateTimestampbossdatd;privateStringrecordlock;privateStringrecordstatus;privateStringrecordshow;privateStringdepartmentcode;privateStringenterprisecode;有错吗?引用2楼的回复:
org.hibernate.hql.ast.QuerySyntaxException:Unabletolocateappropriateconstructoronclass找不到合适的构造方法。selectBuyPlanning(t.id,t.pcode,t.pdatd,t.entryusername,t.bossdatd,t.recordlock,t.records……
解决方案八:
publicclassBuyPlanningextendsAbstractBuyPlanningimplementsjava.io.Serializable{//Constructors/**defaultconstructor*/publicBuyPlanning(){}/**minimalconstructor*/publicBuyPlanning(Integerid){super(id);}/**fullconstructor*/publicBuyPlanning(Integerid,Stringpcode,Timestamppdatd,Stringentryusername,Timestampbossdatd,Stringrecordlock,Stringrecordstatus,Stringrecordshow,Stringdepartmentcode,Stringenterprisecode){super(id,pcode,pdatd,entryusername,bossdatd,recordlock,recordstatus,recordshow,departmentcode,enterprisecode);}}和这个publicabstractclassAbstractBuyPlanningimplementsjava.io.Serializable{//FieldsprivateIntegerid;privateStringpcode;privateTimestamppdatd;privateStringentryusername;privateTimestampbossdatd;privateStringrecordlock;privateStringrecordstatus;privateStringrecordshow;privateStringdepartmentcode;privateStringenterprisecode;//Constructors/**defaultconstructor*/publicAbstractBuyPlanning(){}/**minimalconstructor*/publicAbstractBuyPlanning(Integerid){this.id=id;}/**fullconstructor*/publicAbstractBuyPlanning(Integerid,Stringpcode,Timestamppdatd,Stringentryusername,Timestampbossdatd,Stringrecordlock,Stringrecordstatus,Stringrecordshow,Stringdepartmentcode,Stringenterprisecode){this.id=id;this.pcode=pcode;this.pdatd=pdatd;this.entryusername=entryusername;this.bossdatd=bossdatd;this.recordlock=recordlock;this.recordstatus=recordstatus;this.recordshow=recordshow;this.departmentcode=departmentcode;this.enterprisecode=enterprisecode;}没有问题啊引用4楼的回复:
你的fullconstructor和minimalconstructor检查这两个构造函数的数据类型和你配置文件里定义的是否匹配。下面的链接供你参考。http://blog.csdn.net/yangsp1/article/details/4375910
解决方案九:
怎么搞,我也是这个问题
解决方案十:
我觉得你*.hbm.xml文件跟你的pojo类*.java的数据类型没有对应