异常信息: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. 论文笔记 《Maxout Networks》 && 《Network In Network》

    论文笔记 <Maxout Networks> && <Network In Network> 发表于 2014-09-22   |   1条评论 出处 maxo ...

  2. JAVA二叉树的创建以及各种功能的实现

    直接上代码了,代码说得很清楚了 package BTree; public class BTree { private Node root; private class Node { private ...

  3. python类的使用与多文件组织

    多文件的组织 跨目录级导入模块 from ..xxfile import xxmodule #从上级目录中的xxfile中导入xxmodule import xxsub_dir.xxfile #从xx ...

  4. GZIP压缩占用CPU大吗?

    http://blog.csdn.net/hguisu/article/details/7793038 Filter之——GZIP全站压缩 http://www.cnblogs.com/jbelial ...

  5. SGU 263. Towers

    各种操作: put x c:表示在第 x 列上增加 c 个积木(c>0). tput t x c:表示在塔 t 的第 x 列上增加 c 个积木(c>0). towers:询问共有几座塔. ...

  6. docker容器中文件的上传与下载

    原文地址:传送门 1.上传文件 docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH [OPTIONS]:保持源目标中的链接,例: docker cp ...

  7. CentOS7安装私有gitlab

    1.安装依赖包 yum install -y curl policycoreutils openssh-server openssh-clients postfix systemctl start p ...

  8. bootstrap bootstrapvalidator插件+adjax验证使用

    1.利用bootstrap Validator表单验证进行表单验证需要如下CSS和JS. <link rel="stylesheet" type="text/css ...

  9. 最短路&生成树&二分图匹配&费用流问题

    最短路 题意理解,建图 https://vjudge.net/problem/UVALive-4128 飞机票+行程建图 https://vjudge.net/problem/UVALive-3561 ...

  10. 数据库SQL归纳(一)

    SQL功能分类 SQL 功能 动 词 数据定义 DDL CREATE.ALTER.DROP 数据查询 DQL SELECT 数据更改 DML INSERT.UPDATE.DELETE 数据控制 DCL ...