zoukankan      html  css  js  c++  java
  • Hibernate异常:Unable to locate appropriate constructor on class

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

    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类里面没有对应的构造方法

      注意:构造方法的参数都得对应才行。此外参数不能是Timestamp类型,有Timestamp类型的参数,也会报此错。

      解决方案:加上对应的构造参数即可。

    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();
        }
  • 相关阅读:
    149、你知道空类的大小是多少吗?
    hdoj--2682--Tree()
    hdoj--5053--the Sum of Cube(水)
    Codeforces--602A--Two Bases(水)
    poj--1637--Sightseeing tour(网络流,最大流判断混合图是否存在欧拉图)
    poj--1149--PIGS(最大流经典建图)
    poj--1459--Power Network(最大流,超级源超级汇)
    hdoj--3549--Flow Problem(最大流)
    poj--1237--Drainage Ditches(最大流)
    nyoj--38--布线问题(克鲁斯卡尔)
  • 原文地址:https://www.cnblogs.com/goloving/p/7645743.html
Copyright © 2011-2022 走看看