当前位置:网站首页>When splicing HQL, the new field does not appear in the construction method
When splicing HQL, the new field does not appear in the construction method
2022-04-23 14:45:00 【Luo Luo's 1024】
Problem description
In the use of hibernate Splicing hql when , The new field does not appear in the construction method ( Here's a simplified version , The real situation is much more complicated )
// Entity class
public class Tmd {
private String CBh;
private Integer NSjzzaqxx;
//private String CAjysly;// Add a new field
public static final String cTmdConstructorFields = "(CBh,NSjzzaqxx)";
//public static final String cTmdConstructorFields = "(CBh,NSjzzaqxx,CAjysly)";// Add new fields to the constructor
//......Constructos......
//......getter/setter......
}
// Tool class
public class DatamodelUtils{
public static String CTmdConstructorFields = Tmd.cTmdConstructorFields;
}
adopt Hibernate Query object , Use here select new The way ,SQL How many parameters does the object in have , Entity classes should also have constructors with the same data type and number of parameters
StringBuilder hql = new StringBuilder();
hql.append("select new ").append("com.luo.Tmd").append(DatamodelUtils.CTmdConstructorFields);
This is what runs on the server , Because of the need , I am here Tmd Added a new field CAjysly, The constructor has also been modified , Finally, I put the revised Tmd.class The work put on the test environment is currently work in , Restart project , Report errors
Caused by: org.springframework.orm.hibernate3.HibernateQueryException: Unable to locate appropriate constructor on class .....
Read the log , Found no fields I added , The last one is hql That's true
select new com.luo.Tmd(CBh,NSjzzaqxx)
Why don't I add new fields ?
Cause analysis :
After adding a field , The code is not compiled
Then I immediately go to the generation environment to check Tmd.class, See if I didn't compile , Subsequent use arthas Went to see Tmd.class, It is found that the new field exists , There are also... In the constructor , At this time, I am very confused
// Before modification DatamodelUtils.class
public static String CTmdConstructorFields = "(CBh,NSjzzaqxx)";
And then look at it DatamodelUtils.CTmdConstructorFields
value , It turns out to be "(CBh,NSjzzaqxx)"
, It's still the original value , At this point, I probably understand , My replacement file is just Tmd.class, however DatamodelUtils.class It's still the same , Did not reload , Because the server didn't detect DatamodelUtils The change of
Solution :
Yes DatamodelUtils Recompile , Publish to the test environment
Reflection summary :
In the case of an incremental replacement file , Modification of constants , Remember where constants are used , Have to recompile , And then release
版权声明
本文为[Luo Luo's 1024]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231426114272.html
边栏推荐
- 金九银十,入职字节跳动那一天,我哭了(蘑菇街被裁,奋战7个月拿下offer)
- Chapter 7 of JVM series -- bytecode execution engine
- 如何打开Win10启动文件夹?
- 51单片机+LCD12864液晶显示的俄罗斯方块游戏,Proteus仿真、AD原理图、代码、论文等
- JumpServer
- MySQL报错packet out of order
- [untitled]
- OpenFaaS实战之四:模板操作(template)
- UML project example -- UML diagram description of tiktok
- Don't you know the usage scenario of the responsibility chain model?
猜你喜欢
DVWA之暴力破解(Brute Force)Low-->high
What is the main purpose of PCIe X1 slot?
[jz46 translate numbers into strings]
交通灯系统51单片机设计(附Proteus仿真、C程序、原理图及PCB、论文等全套资料)
【工厂模式详解】工厂方法模式
编程哲学——自动加载、依赖注入与控制反转
单相交交变频器的Matlab Simulink建模设计,附Matlab仿真、PPT和论文等资料
《JVM系列》 第七章 -- 字节码执行引擎
Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
SHT11传感器的温度湿度监控报警系统单片机Proteus设计(附仿真+论文+程序等)
随机推荐
拼接hql时,新增字段没有出现在构造方法中
成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
Solve the problem of SSH configuration file optimization and slow connection
[jz46 translate numbers into strings]
QT interface optimization: double click effect
ASEMI三相整流桥和单相整流桥的详细对比
《JVM系列》 第七章 -- 字节码执行引擎
想要成为架构师?夯实基础最重要
Arduino for esp8266串口功能简介
The art of automation
capacitance
DS1302的电子万年历_51单片机,年月日、星期、时分秒、农历和温度,带闹钟,全套资料
Vous ne connaissez pas encore les scénarios d'utilisation du modèle de chaîne de responsabilité?
How do I open the win10 startup folder?
AT89C52 MCU frequency meter (1Hz ~ 20MHz) design, LCD1602 display, including simulation, schematic diagram, PCB and code, etc
A blog allows you to learn how to write markdown on vscode
PCIe X1 插槽的主要用途是什么?
【工厂模式详解】工厂方法模式
Four ways of SSH restricting login
51单片机+LCD12864液晶显示的俄罗斯方块游戏,Proteus仿真、AD原理图、代码、论文等