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 ...
随机推荐
- Docker概览
Docker.xmind下载
- 【转载】JAVA多线程和并发基础面试问答
转载自这里. 多线程和并发问题是Java技术面试中面试官比较喜欢问的问题之一.在这里,从面试的角度列出了大部分重要的问题,但是你仍然应该牢固的掌握Java多线程基础知识来对应日后碰到的问题.(校对注: ...
- vivo手机的坑-禁止微信浏览器网页点击图片,图片会自动放大
这个坑让我郁闷极了,之前我的手机在微信浏览器打开网页点击图片时,啥事也没有 现在,咋回事,变了呢! 现在我打开微信浏览器网页面html,点击一个img标签的图片,图片会自动满屏放大,吓死宝宝了.其他人 ...
- centos7.5安装opendesktop
1.下载地址 http://gnome-look.org/ 2.安装 chmod +x opendesktop-app-3.1.3-1-x86_64.AppImage ./opendesktop-ap ...
- 使用CMake,且在GCC编译时指定相对源代码路径选项BUG的问题
CMake的build.make,每次都是cd xxx目录,然后再编译 而编译时,GCC会取当前路径保存进调试信息的DT_AT_comp_dir,GCC的编译器选项-fdebug-prefix-map ...
- python怎么解压压缩的字符串数据
范例1: gzip import StringIO import gzip compresseddata = gzip方式压缩的字符串(html) compressedstream = StringI ...
- 【我要学python】爬虫准备之了解基本的html标签
HTML 标题 <h1>This is a heading</h1> HTML 段落 <p>This is a paragraph.</p> HTML ...
- 关于matplotlib,你要的饼图在这里
Table of Contents 1 官方Demo 2 将实际数据应用于官方Demo 3 一些改善措施 3.1 重新设置字体大小 3.2 设置显示颜色,Method 1: 3.3 设置显 ...
- 【转】【python】装饰器的原理
写在前面: 在开发OpenStack过程中,经常可以看到代码中的各种注解,自己也去查阅了资料,了解了这是python中的装饰器,因为弱类型的语言可以将函数当成返回值返回,这就是装饰器的原理. 虽然说知 ...
- Friends number NBUT - 1223 (暴力打表)
Paula and Tai are couple. There are many stories between them. The day Paula left by airplane, Tai s ...