当前位置:网站首页>拼接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
边栏推荐
- Docker (V) MySQL installation
- ArrayList集合基本使用
- setcontext getcontext makecontext swapcontext
- 51单片机+LCD12864液晶显示的俄罗斯方块游戏,Proteus仿真、AD原理图、代码、论文等
- Introduction to the use of semaphore for inter thread control
- QT actual combat: Yunxi calendar
- Processing MKDIR: unable to create directory 'AAA': read only file system
- Redis源码分析之PSYNC同步
- LotusDB 设计与实现—1 基本概念
- Golang 对分片 append 是否会共享数据
猜你喜欢

redis的五种数据类型

单片机的函数信号发生器,输出4种波形,频率可调,原理图,仿真和C程序

全连接层的作用是什么?

8.5 循环神经网络简洁实现

TLS/SSL 协议详解 (28) TLS 1.0、TLS 1.1、TLS 1.2之间的区别

KVM learning resources

QT interface optimization: QT border removal and form rounding

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

常见存储类型和FTP主被动模式解析

ArrayList集合基本使用
随机推荐
First acquaintance with STL
C语言知识点精细详解——初识C语言【1】
Uni app message push
循环队列的基本操作,你学会了吗?
async void 导致程序崩溃
51 MCU flowers, farmland automatic irrigation system development, proteus simulation, schematic diagram and C code
Introduction to the use of countdownlatch and cyclicbarrier for inter thread control
API Gateway/API 网关(二) - Kong的使用 - 负载均衡Loadbalance
After entering the new company, the operation and maintenance engineer can understand the deployment of the system from the following items
全连接层的作用是什么?
一些小小小小记录~
Basic regular expression
MySQL同步Could not find first log file name in binary log index file错误
顺序表的操作,你真的学会了吗?
常见存储类型和FTP主被动模式解析
Branch statement of process control
交通灯系统51单片机设计(附Proteus仿真、C程序、原理图及PCB、论文等全套资料)
TUN 设备原理
c语言在结构体传参时参数压栈问题
LM317的直流可调稳压电源Multisim仿真设计(附仿真+论文+参考资料)