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:)
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的更多相关文章
- 【Hibernate】Unable to locate appropriate constructor on class原因分析
通常我们喜欢将hql查询结果封装到POJO对象syntax:select new POJO(id,name) from POJO ; 这种封装需要POJO类提供对应构造器,POJO(id,name)构 ...
- Unable to locate appropriate constructor on class异常
一般出现Unable to locate appropriate constructor on class这个异常,都是实体类的带参数的构造方法和使用查询语句出现偏差,两个地方的代码如下: 一般都是第 ...
- Unable to locate appropriate constructor on class报错
在项目开发中,使用Hibernate里的JPA criteria查询,但是在写完之后使用时,会报错:Unable to locate appropriate constructor on class, ...
- Hibernate 异常 —— Unable to instantiate default tuplize
出现这个异常 —— Unable to instantiate default tuplizer ,是 Hibernate 的映射文件(*.hbm.xml)导致的.仔细检查一下工程里的映射文件吧. 笔 ...
- 出现Unable to locate appropriate constructor on class 错误可能的原因
1)参数构造器的参数类型是否正确2)参数构造器的顺序和hql中的顺序是否一致3)参数构造器的参数个数是否和hql中的个数一致4)参数构造器的参数类型是否TimeStamp
- 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 ...
- Unable to locate secure storage module异常的解决方案
org.eclipse.equinox.security.storage.StorageException: Unable to locate secure storage module 该异常同样是 ...
- 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 ...
- 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 ...
随机推荐
- How To Install Nginx on Ubuntu 16.04 zz
Introduction Nginx is one of the most popular web servers in the world and is responsible for hostin ...
- python和语法糖
语法糖(syntactic sugar)是指编程语言中可以更容易的表达一个操作的语法,它可以使程序员更加容易去使用这门语言:操作可以变得更加清晰.方便,或者更加符合程序员的编程习惯.(百度百科的 ...
- python 几种循环性能测试: while, for, 列表生成式, map等
直接上代码: #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/07/24 16:23 import itertools imp ...
- 【hdoj_2082】找单词
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2082 此题采用母函数的知识求解,套用母函数模板即可: http://blog.csdn.NET/ten_s ...
- 【JBPM4】任务节点-任务分配swimlane
swimlane泳道,几个任务受理人相同的任务节点,可以划分为一个泳道 JPDL <?xml version="1.0" encoding="UTF-8" ...
- 【剑指offer】面试题 28. 对称的二叉树
面试题 28. 对称的二叉树 题目描述 题目:请实现一个函数,用来判断一颗二叉树是不是对称的.注意,如果一个二叉树同此二叉树的镜像是同样的,定义其为对称的. 解答过程 给定一个二叉树,检查它是否是镜像 ...
- 其实参与QtCreator开发也很容易
http://bbs.csdn.net/topics/370241186 10个月前发过一个组建Qt团队,共同研究.学习.完善QtCreator的帖子,不过在为QtCreator提交完一个补丁后,就没 ...
- 洛谷P2590 [ZJOI2008] 树的统计 [树链剖分]
题目传送门 树的统计 题目描述 一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w. 我们将以下面的形式来要求你对这棵树完成一些操作: I. CHANGE u t : 把结点u的权值改为t ...
- FZOJ 2245 动态树(离散+离线+ 树状数组)
Problem 2245 动态树 Accept: 17 Submit: 82Time Limit: 3000 mSec Memory Limit : 65536 KB Problem D ...
- [Atcoder Grand Contest 004] Tutorial
Link: AGC004 传送门 A: …… #include <bits/stdc++.h> using namespace std; long long a,b,c; int main ...