异常信息: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. 从(0)新开始vue2.0【安装】

    安装node:测试安装结果:node -v 安装cnpm(如果你可以***,可以不安装) 安装webpack:npm install webpack -g npm install vue-cli -g ...

  2. coercing to Unicode错误的一个解决办法

    http://blog.csdn.net/happen23/article/details/46683813

  3. CentOS 7.4 上如何安装 tomcat 9

    本文将详细讲解在 CentOS 7.4 系统上如何安装tomcat 9,tomcat是没有32位和64位之分的. 创建tomcat的安装路径 首先在/usr/local/下建立一个tomcat的文件夹 ...

  4. NBUT 1220 SPY

    $map$,简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<algorit ...

  5. 如何用jmeter对websockt和protobuf进行压力测试

    参考代码:https://github.com/hutao722/kekexinxin 这是基于Jmeter WebsocketSampler的插件,支持对基于websocket和protobuf的服 ...

  6. ubuntu的boot分区报警,删除无用内核文件。

    1. 查看当前使用内核:uname -r4.4.0-97-generic 2. 查看安装的内核dpkg --list 'linux-image*' 3. 删除旧内核sudo apt-get remov ...

  7. 单能X射线产生方法

    主要是荧光 利用布拉格准则, 关键词如下.. 国内有些专利 monochromating crystal spectrometer 物理实验设备名称翻译 ... 单色光检糖计 monochromati ...

  8. 求高精度幂(poj1001)

    Description Problems involving the computation of exact values of very large magnitude and precision ...

  9. 【codevs1074】食物链

    [codevs1074]食物链 2001年NOI全国竞赛  时间限制: 3 s  空间限制: 64000 KB  题目等级 : 钻石 Diamond   题目描述 Description 动物王国中有 ...

  10. 【DFS】奇怪的电梯

    奇怪的电梯 题目描述 有一天桐桐做了一个梦,梦见了一种很奇怪的电梯.大楼的每一层楼都可以停电梯,而且第i层楼(1≤i≤N)上有一个数字K:(0≤Ki≤N).电梯只有四 个按钮:开,关,上,下.上下的层 ...