当前位置:网站首页>拼接hql时,新增字段没有出现在构造方法中
拼接hql时,新增字段没有出现在构造方法中
2022-04-23 14:26:00 【罗罗的1024】
问题描述
在使用hibernate拼接hql时,新增字段竟然没有出现在构造方法中(下面是简化版,真实情况要复杂的多)
//实体类
public class Tmd {
private String CBh;
private Integer NSjzzaqxx;
//private String CAjysly;//新加字段
public static final String cTmdConstructorFields = "(CBh,NSjzzaqxx)";
//public static final String cTmdConstructorFields = "(CBh,NSjzzaqxx,CAjysly)";//新增字段添加进构造器
//......Constructos......
//......getter/setter......
}
//工具类
public class DatamodelUtils{
public static String CTmdConstructorFields = Tmd.cTmdConstructorFields;
}
通过Hibernate查询对象,这里使用select new 的方式,SQL里的对象有多少个参数,实体类也要有数据类型和参数个数一致的构造器
StringBuilder hql = new StringBuilder();
hql.append("select new ").append("com.luo.Tmd").append(DatamodelUtils.CTmdConstructorFields);
服务器上跑的就是这个,因为需求,我在Tmd新增了一个字段CAjysly,构造器也进行了修改,最后我把修改后的 Tmd.class 放到测试环境上的工作目前work中,重启项目,报错
Caused by: org.springframework.orm.hibernate3.HibernateQueryException: Unable to locate appropriate constructor on class .....
看了日志,发现没有我新增的字段,最后拼接的hql是这样的
select new com.luo.Tmd(CBh,NSjzzaqxx)
为啥我新增的字段没有呢?
原因分析:
是不是新增了字段后,代码没有编译上
随后我马上到生成环境上查看Tmd.class,看看是不是我没有编译上,随后使用arthas去看了Tmd.class,发现新增字段是存在的,构造器里面也有,此时的我很懵逼
//修改之前的DatamodelUtils.class
public static String CTmdConstructorFields = "(CBh,NSjzzaqxx)";
然后看看DatamodelUtils.CTmdConstructorFields
值,发现竟是 "(CBh,NSjzzaqxx)"
,还是原来的值,此时大概就明白了,我出的替换文件仅仅是Tmd.class,但是DatamodelUtils.class还是原来的,并没有重新加载,因为服务器根本没有检测到DatamodelUtils的变化
解决方案:
对DatamodelUtils重新进行编译,发布到测试环境上
反思总结:
在出增量替换文件的情况下,对于常量的修改,要切记使用到常量的地方,都要重新进行编译,然后发布
版权声明
本文为[罗罗的1024]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_42224683/article/details/124245703
边栏推荐
- flannel 原理 之 子网划分
- API Gateway/API 网关(四) - Kong的使用 - 集成Jwt和熔断插件
- 关于在vs中使用scanf不安全的问题
- 51单片机的花卉、农田自动浇水灌溉系统开发,Proteus仿真,原理图和C代码
- Master in minutes --- ternary operator (ternary operator)
- 电子秤称重系统设计,HX711压力传感器,51单片机(Proteus仿真、C程序、原理图、论文等全套资料)
- OpenSSH的升级、版本号的修改
- L'externalisation a duré quatre ans.
- Eight way responder system 51 Single Chip Microcomputer Design [with Proteus simulation, C program, schematic diagram, PCB files, component list and papers, etc.]
- 单相交交变频器的Matlab Simulink建模设计,附Matlab仿真、PPT和论文等资料
猜你喜欢
Branch statement of process control
On the insecurity of using scanf in VS
Nacos uses demo as configuration center (IV)
外包幹了四年,廢了...
51 MCU + LCD12864 LCD Tetris game, proteus simulation, ad schematic diagram, code, thesis, etc
Tongxin UOS uninstall php7 2.24, install php7 4.27 ; Uninstall and then install PHP 7.2.34
四层和八层电梯控制系统Proteus仿真设计,51单片机,附仿真和Keil C代码
外包干了四年,废了...
Man man notes and @ reboot usage of crontab
Electronic perpetual calendar of DS1302_ 51 single chip microcomputer, month, day, week, hour, minute and second, lunar calendar and temperature, with alarm clock and complete set of data
随机推荐
C语言p2选择分支语句详解
Web page, adaptive, proportional scaling
Proteus simulation design of four storey and eight storey elevator control system, 51 single chip microcomputer, with simulation and keil c code
Flop effect
查找水仙花数-for循环实践
Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)
LotusDB 设计与实现—1 基本概念
Electronic scale weighing system design, hx711 pressure sensor, 51 single chip microcomputer (proteus simulation, C program, schematic diagram, thesis and other complete data)
grep无法重定向到文件的问题
Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
Find daffodils - for loop practice
Solve the problem of SSH configuration file optimization and slow connection
一篇博客让你学会在vscode上编写markdown
555 timer + 74 series chip to build eight way responder, 30s countdown, proteus simulation, etc
LLVM - 生成局部变量
修改Firebase Emulators的默认侦听IP
Qt界面优化:鼠标双击特效
直流可调稳压电源的Proteus仿真设计(附仿真+论文等资料)
JS recursion (1)
Parameter stack pressing problem of C language in structure parameter transmission