org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class XXX解决

Unable to locate appropriate constructor on class报错原因以及解决方案 再使用HQL语句通过封装查询时,会添加一个虚拟的实体类  例如 select new com.musicworld.vo.ComUserSong(c.commentId,c.commentTime,c.content,c.userinfo.userName) from Comment c 这种封装需要实体类提供对应构造器 构造方法 public ComUserSong(In 阅读详情

环境

MyEclipse 8.6+Hibernate3.2

 

问题

 

使用Hibernate出现如下错误:

 

org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.lo.entities.User] [select new User(u.userName,u.userAge) from com.lo.entities.User u]
	at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
	at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
	at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
	at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:261)
	at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
	at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
	at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
	at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
	at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
	at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
	at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
	at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1651)
	at com.ol.entities.LoTest.testListByHQL(LoTest.java:133)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


 

解决

 

这是出现错误的地方使用的HQL

String hql="select new User(u.userName,u.userAge) from User u";

 

当查询某个实体类的部分属性然后封装成List时,需要该属性构成的构造器。

 

SpringBoot整合Mybaitis-使用mapper注解 上一篇博文已经详细介绍了SpringBoot环境搭建过程,这一节介绍一下SpringBoot整合Mybatis。 SpringBoot整合Mybatis 方式1:mapper使用注解 项目结构 1:准备数据库数据和配置数据源 #数据源必填项 spring.datasource.driver-class-name= com.mysql.jdbc.Driver ... 阅读详情

相关推荐

在 SAP BTP ABAP Environment 里把 ATC 跑成流水线:定时检查 + 告警邮件,一次打通

摘要 本文介绍了如何在SAP BTP ABAP环境中实现ATC检查的自动化流程。通过将ATC与质量体系结合,构建从检查到通知的完整闭环:使用Custom Code Analysis Project定义检查范围,通过Application Jobs实现定时调度,利用标准CDS View读取结果,最后开发通知作业发送告警邮件。文章重点阐述了云环境下不同于On-Premise的实现思路,包括Test Variant设计、作业编排模板应用等关键环节,并提供了可落地的代码示例。这种自动化方案能有效解决人工检查的滞后性

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 119

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...

weixin_33863087的博客 308

PMSM控制系列文章进阶-8.电流、角度采样及其同步

摘要:本文分析了高低压电机在电流和角度采样中的不同方案选择。高压电机采用霍尔传感器和旋变进行隔离采样,低压电机则使用shunt电阻和磁编码器以降低成本。重点讨论了采样时间补偿问题:电流采样需与PWM周期同步,角度采样需考虑传感器延迟;通过park变换和反park变换时需补偿采样与发波的时间差,提出了通过测试母线电流或Ud变化来验证补偿时间准确性的方法。文中还介绍了对传感器信号进行软解码处理的方法,包括消除直流偏置、增益误差和正交误差等参数的自学习过程。

weixin_41343701的博客 581

org.hibernate.hql.internal.ast.QuerySyntaxException 查询操作时报错-解决

一、报错:org.hibernate.hql.internal.ast.QuerySyntaxException: XXXis not mapped [FROM XXX WHERE owner = ?1] 具体报错: Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: student is not mapped [FROM student WHERE owner = ?1] Caused by: java.lang.Ille.

心有谦谦结 1万+

org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class xxx

Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [org.hibDemo.pojo.SysRole] [select new SysRole(u.rid,u.name) from org.hibDemo.p

renjingkai的博客 3006

Unable to locate appropriate constructor on class

 在使用hql的时候,有时候查询的结果不需要所有字段只是部分字段,于是做如下修改。 String hql = "select new TForm4Notice(id,title) from TForm4Notice where isPub =1 order by showOrder desc,createTime desc";  如果只是改了hql语句,其他地方没有配置,会直接报下面的错误。...

七月的专栏 2651

springboot整合mybatis mapper注入时报错could not autowire,几种解决方案

问题提出 springboot整合mybatis mapper注入时,报错could not autowire(IDE为IntelliJ IDEA): 虽然红线标出报错,但运行和使用没有问题。看着红线报错不舒服,搜索得到了几种方案,整合在一起。 问题解决 1. 使用@Resource注解替换@Autowired 如下: @Autowired与@Resource的区别(@Autowired和@R...

JellyfishMIX 的博客 4715

IDEA整合Springboot和Mybatis中xml配置找不到Mapper问题解决

准备用Springboot整合Mybatis练习时,出现了两个问题: 一、在service中注入mapper时说Autowired没有实体Bean,因为在mapper接口上只添加了@Mapper注解,应该再添加一个@Repository注解 二、找不到mapper问题,网上都说用@MapperScan,我用后毫无效果,运行起来依然报错。后来搜到一个大佬的分析,从Mybatis源码追踪到了问题。 说是IDEA不会编译java包下的xml文件,eclipse不会有这个问题。既然都没编译,那当然找不到咯,需要在p

weixin_42509364的博客 2026

SpringBoot整合Mybatis扫描不到Mapper的问题

闲来无事,想学学springboot,开始搭建一个项目,但是一直显示mapper扫描不到的错误: “Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Er

SU坡馒的博客 10万+

记一次SpringBoot整合MyBatis时找不到Mapper.xml的BUG定位

1、前因 最近开始写我的博客系统了,想着先把登录注册功能写了,框架采用SpringBoot+SpringSecurity+MyBatis,于是想着先把SpringBoot和MyBatis整合,谁知道,这一整合就整出问题了。 2、BUG定位 首先先给大家复现下我的BUG,下面是我的工程结构: 这个代码是没问题,但是启动项目的时候就报了个错,这个错叫“Invalid bound statement(not found) ”,我百度了下,是说Mapper.xml文件没找到,有人说是因为Mapper.xml文件在

AlaGeek的博客 1255

MyBatis-Plus找不到Mapper.xml文件的解决方法

Invalid bound statement (not found)

u011447905的专栏 1万+

springBoot整合mybatis

离职到了新公司,之前没有用springBoot整合过,特此记录。 1.创建一个springBoot项目 添加依赖 修改pom.xml,改mysql的版本,添加xml的扫描方式 <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <sco

一种感觉的博客 1万+

Springboot 整合 Mybatis-plus时(mapper文件扫描不到)

Springboot 整合 Mybatis-plus 出错 报错描述: Property ‘mapperLocations’ was not specified or no matching resources found 问题原因:springboot启动时,src/main/java下只会扫描加载.java文件,而我的mapper.xml是放在src/main/java目录下的。需要指定mapper.xml位置。 1、第一步 在application.properties文件中添加 mapper-loc

weixin_45429720的博客 1万+

mybatis注册了mapper但是还是报错_SpringBoot 2.X整合Mybatis

1、创建工程环境勾选Web、Mybatis、MySQL,如下 依赖如下<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> ...

weixin_39805364的博客 569

SpringBoot项目整合Mybatis时Mapper.xml文件的三种存放位置方式

maven 引入依赖-- pagehelper 分页插件 --> < dependency > < groupId > com.github.pagehelper </ groupId > < artifactId > pagehelper-spring-boot-starter </ artifactId > </ dependency > <!

黄彪博客 3414

springboot整合mybatis报错

springboot整合mybatis报错 项目结构 pom.xml <dependencies> <!--spring-web--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId&gt

qq_43445045的博客 1095

SpringBoot2.x整合MyBatis通用Mapper4

通用 Mapper4 是一个可以实现任意 MyBatis 通用方法的框架,项目提供了常规的增删改查操作以及Example 相关的单表操作。通用 Mapper 是为了解决 MyBatis 使用中 90% 的基本操作,使用它可以很方便的进行开发,可以节省开发人员大量的时间。 【官方文档】 https://github.com/abel533/Mapper/wiki 【maven依赖】 http://...

日拱一卒 1597

SpringBoot整合Mybatis Mapper扫描问题

工程结构 SpringBoot starter默认扫描的是stater所在包及其子包中 这样的结构如果不使用MapperScan注解是无法扫描到UserMapper的。 使用@Autowired启动会报错 Field userMapper in com.neusiri.controller.HelloController required a bean of type 'com.neusiri.mapper.UserMapper' that could not be found. ...

zdj18166896501的博客 4280

SpringBoot整合Mybatis(详解,一看就会)

在resource创建好之后,我们在resource目录下创建application.yml,创建完之后写数据库配置文件,根据自己的 数据库和数据库账号和密码进行更改,改成自己的,以及端口,我这边端口是8081,根据自己可以修改端口,默认是 8080。注:本类中不要忘记写@service,以及依赖注入UserMapper,刚开始可以直接复制我的代码,后面自己去慢慢理解。至此我们的SpringBoot+Mybatis已经整合完毕了 我们运行项目,显示如下,我们已经运行完毕且没有错误。delete用于删除。

m0_67267524的博客 7899

不同细胞类型的显微图像数据集

不同细胞类型的显微图像数据集数据说明:该数据集包含猫网织红细胞(一种没有细胞核的不成熟的红细胞,在适当染色时呈颗粒状或网状)的图像和标签该数据被用作以下论文的基础--使用卷积神经网络确定猫网织红细胞百分比。该数据集使用兽医容易获得的设备创建:标准实验室显微镜和两种类型的相机:基本显微镜相机和智能手机相机内容:主要的图像数据在图像文件夹中,标签在标签文件夹中。一些测试图像也包括在测试文件夹中、用替代设备拍摄的,共有2333张相关的图片。

上一篇: org.hibernate.exception.ConstraintViolationException: could not insert解决
下一篇: org.hibernate.HibernateException: Errors in named queries解决
Wentasy
博客等级 码龄15年 2390粉丝 673原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值