Hibernate異常:Unable to locate appropriate constructor on class

  異常信息:org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on classjava

org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.vrv.cems.assets.domain.Device] [select new Device(d.id,d.diskSize,d.diskSerial,d.registerTime) from com.vrv.cems.assets.domain.Device as d where d.matherBoard=:matherBoard] at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54) at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47) at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:263) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:187) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:138) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)

  緣由:Device類裏面沒有對應的構造方法app

  注意:構造方法的參數都得對應才行。此外參數不能是Timestamp類型,有Timestamp類型的參數,也會報此錯。dom

  解決方案:加上對應的構造參數便可。this

public Device(String id,Integer diskSize ,String diskSerial) { super(); this.id = id; this.diskSize = diskSize; this.diskSerial = diskSerial; }
public List<Device> queryByMatherBoardId(String matherBoardId) { String hql = "select new Device(d.id,d.diskSize,d.diskSerial) from Device as d where d.matherBoard=:matherBoard"; return this.getSession().createQuery(hql) .setParameter("matherBoard", matherBoardId).list(); }
相關文章
相關標籤/搜索