当前位置:网站首页>拼接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
边栏推荐
- TLS/SSL 协议详解 (28) TLS 1.0、TLS 1.1、TLS 1.2之间的区别
- I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another
- QT interface optimization: QT border removal and form rounding
- Outsourcing for four years, abandoned
- 51 MCU flowers, farmland automatic irrigation system development, proteus simulation, schematic diagram and C code
- 51单片机的花卉、农田自动浇水灌溉系统开发,Proteus仿真,原理图和C代码
- Logical volume creation and expansion
- QT actual combat: Yunxi calendar
- ArrayList集合基本使用
- ansible及常用模块的使用
猜你喜欢
x509证书cer格式转pem格式
四层和八层电梯控制系统Proteus仿真设计,51单片机,附仿真和Keil C代码
一篇博客让你学会在vscode上编写markdown
51单片机的花卉、农田自动浇水灌溉系统开发,Proteus仿真,原理图和C代码
Parameter stack pressing problem of C language in structure parameter transmission
数组模拟队列进阶版本——环形队列(真正意义上的排队)
Tongxin UOS uninstall php7 2.24, install php7 4.27 ; Uninstall and then install PHP 7.2.34
一款不错的工具:aardio
XX project structure notes
一个月把字节,腾讯,阿里都面了,写点面经总结……
随机推荐
MySQL同步Could not find first log file name in binary log index file错误
Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)
After entering the new company, the operation and maintenance engineer can understand the deployment of the system from the following items
QT actual combat: Yunxi chat room
AT89C51单片机的数字电压表开发,量程0~5V,proteus仿真,原理图PCB和C程序等
Qt实战:云曦聊天室篇
Master in minutes --- ternary operator (ternary operator)
八路抢答器系统51单片机设计【附Proteus仿真、C程序、原理图及PCB文件、元器件清单和论文等】
x509证书cer格式转pem格式
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
C语言p2选择分支语句详解
顺序栈的基本操作
JumpServer
流程控制之分支语句
555定时器+74系列芯片搭建八路抢答器,30s倒计时,附Proteus仿真等
Redis cluster 原理
TLS/SSL 协议详解 (30) SSL中的RSA、DHE、ECDHE、ECDH流程与区别
redis 模块编程中 key value的生命周期
Tongxin UOS uninstall php7 2.24, install php7 4.27 ; Uninstall and then install PHP 7.2.34
基于单片机的DS18B20的数字温度监控报警系统设计【LCD1602显示+Proteus仿真+C程序+论文+按键设置等】