异常信息: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:)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:)

  原因: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();
}

Hibernate异常:Unable to locate appropriate constructor on class的更多相关文章

  1. 【Hibernate】Unable to locate appropriate constructor on class原因分析

    通常我们喜欢将hql查询结果封装到POJO对象syntax:select new POJO(id,name) from POJO ; 这种封装需要POJO类提供对应构造器,POJO(id,name)构 ...

  2. Unable to locate appropriate constructor on class异常

    一般出现Unable to locate appropriate constructor on class这个异常,都是实体类的带参数的构造方法和使用查询语句出现偏差,两个地方的代码如下: 一般都是第 ...

  3. Unable to locate appropriate constructor on class报错

    在项目开发中,使用Hibernate里的JPA criteria查询,但是在写完之后使用时,会报错:Unable to locate appropriate constructor on class, ...

  4. Hibernate 异常 —— Unable to instantiate default tuplize

    出现这个异常 —— Unable to instantiate default tuplizer ,是 Hibernate 的映射文件(*.hbm.xml)导致的.仔细检查一下工程里的映射文件吧. 笔 ...

  5. 出现Unable to locate appropriate constructor on class 错误可能的原因

    1)参数构造器的参数类型是否正确2)参数构造器的顺序和hql中的顺序是否一致3)参数构造器的参数个数是否和hql中的个数一致4)参数构造器的参数类型是否TimeStamp

  6. org.hibernate.UnknownEntityTypeException: Unable to locate persister: com.hibernate2.pojo.News at org.hibernate.internal.SessionFactoryImpl.locateEntityPersister(SessionFactoryImpl.java:797)

    使用的是hibernate5的方法: ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySetti ...

  7. Unable to locate secure storage module异常的解决方案

    org.eclipse.equinox.security.storage.StorageException: Unable to locate secure storage module 该异常同样是 ...

  8. vue build报copy-webpack-plugin] unable to locate异常的解决方法

    ERROR in [copy-webpack-plugin] unable to locate 'J:\xxx\xxx\xxx\xxx\static' at 'J:\xxx\xxx\xxx\xxx\s ...

  9. org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

    使用Hibernate 插入List数据时出现了以下异常: SLF4J: The requested version 1.6 by your slf4j binding is not compatib ...

随机推荐

  1. ZIP排除指定目录进行压缩

    zip -r glog-0.3.5.zip glog-0.3.5/  -x "glog-0.3.5/doc/*" unzip -v glog-0.3.5.zip 进行查看ZIP的内 ...

  2. [你必须知道的.NET]第二十六回:认识元数据和IL(下)

    发布日期:2009.03.04 作者:Anytao © 2009 Anytao.com ,Anytao原创作品,转贴请注明作者和出处. 说在,开篇之前 书接上回: 第二十四回:认识元数据和IL(上), ...

  3. 前端读者 | 百度前端编码规范(JS)

    本文来自:百度FEX 1 前言 JavaScript在百度一直有着广泛的应用,特别是在浏览器端的行为管理.本文档的目标是使JavaScript代码风格保持一致,容易被理解和被维护. 虽然本文档是针对J ...

  4. 【剑指offer】面试题 16. 数值的整数次方

    面试题 16. 数值的整数次方 题目描述 题目:给定一个double类型的浮点数base和int类型的整数exponent.求base的exponent次方. 解答过程 下面的讨论中 x 代表 bas ...

  5. web资料收集

    Web安全资料:https://github.com/CHYbeta/Web-Security-Learning http://blog.pentestbegins.com/2017/07/21/ha ...

  6. python——聊聊iterable,sequence和iterators

    ---------------------------------------------------------------前言----------------------------------- ...

  7. HTML5+中动态构建列表并填充数据

    部分代码参考demo----<历史上的今天>. 感谢作者的分享,愿好人一生平安,虽然只有两个页面,但是通过这个示例让我学会了5+中如何动态构建列表并填充数据,非常实用. html部分: & ...

  8. 【stl小记】list

    list相当于双向链表,所以快插快删比较方便(链式数据结构的性质),但是随机读取较慢 用一道luogu的水题做一做list,code如下 #include <cstdio> #includ ...

  9. Android,几款apk工具

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 可以查看到链接的设备 可以查看到wifi密码,这个也是个开源的 可以查询驾照学时进度 可 ...

  10. 【BZOJ 2803】【POI 2012】Prefixuffix

    http://www.lydsy.com/JudgeOnline/problem.php?id=2803 核心思想是利用单调性. 因为长度为L的前缀和后缀循环同构是AB和BA的形式,我们设\(f(i) ...