当前位置:网站首页>拼接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
边栏推荐
- JumpServer
- Detailed explanation of C language knowledge points -- first knowledge of C language [1]
- 一款不错的工具:aardio
- 8.4 循环神经网络从零实现
- Four ways of SSH restricting login
- API Gateway/API 网关(二) - Kong的使用 - 负载均衡Loadbalance
- Tongxin UOS uninstall php7 2.24, install php7 4.27 ; Uninstall and then install PHP 7.2.34
- 555 timer + 74 series chip to build eight way responder, 30s countdown, proteus simulation, etc
- Introduction to loan market quotation interest rate (LPR) and loan benchmark interest rate
- 直流可调稳压电源的Proteus仿真设计(附仿真+论文等资料)
猜你喜欢
QT actual combat: Yunxi chat room
AT89C51单片机的数字电压表开发,量程0~5V,proteus仿真,原理图PCB和C程序等
外包干了四年,废了...
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
LM317的直流可调稳压电源Multisim仿真设计(附仿真+论文+参考资料)
查找水仙花数-for循环实践
Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)
AT89C52单片机的频率计(1HZ~20MHZ)设计,LCD1602显示,含仿真、原理图、PCB与代码等
MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
随机推荐
JumpServer
错误:无法远程查找到密钥 “428F7ECC7117F726“
Matrix exchange row and column
Redis源码分析之HSET流程与ziplist
Notes on Visio drawing topology
Tongxin UOS uninstall php7 2.24, install php7 4.27 ; Uninstall and then install PHP 7.2.34
Proteus simulation design of four storey and eight storey elevator control system, 51 single chip microcomputer, with simulation and keil c code
redis 模块编程中 key value的生命周期
Use cases of the arrays class
Branch statement of process control
1分钟看懂执行流程,永久掌握for循环(附for循环案例)
循环队列的基本操作,你学会了吗?
初始c语言大致框架适合复习和初步认识
flannel 原理 之 子网划分
MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
LM317的直流可调稳压电源Multisim仿真设计(附仿真+论文+参考资料)
Redis源码分析之PSYNC同步
OpenSSH的升级、版本号的修改
8.5 循环神经网络简洁实现
I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another