我最近将spring框架从5.0.3升级到5.3.12,将mysql从5.7升级到8。
我在DB中添加了新列,在model类中添加了相应的字段。但是它无法在DB中存储新添加的字段的值。我已经调试了这个程序,这些值是在模型类中修补的,但是在调用simplejdbcinsert之后,这些值不会在DB中持久存在。
密码是这样的-
刀召唤-
logger.debug("Party Insert: " + logStr);
ID = new SimpleJdbcInsert(dataSource).withTableName("TBL_PARTY")
.usingGeneratedKeyColumns("Id").executeAndReturnKey(sqlParams).intValue();模特班-
public class Party extends GenericEntity{
private String partyType, name, partyCode, PANNumber;
private String registrationId;
private String WebsiteAddress;
private boolean isActive = true;
private String externalID;
private double openingBalance, closingBalance;
// new columns - fields
private String temp;
private int tempInt;
private byte tempTyniInt;
private boolean tempBol;
public String getTemp() {
return temp;
}
public void setTemp(String temp) {
this.temp = temp;
}
public String getWebsiteAddress() {
return WebsiteAddress;
}
public void setWebsiteAddress(String websiteAddress) {
WebsiteAddress = websiteAddress;
}
public String getPartyCode() {
return partyCode;
}
public void setPartyCode(String partyCode) {
this.partyCode = partyCode;
}
public String getPartyType() {
return partyType;
}
public void setPartyType(String partyType) {
this.partyType = partyType;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getRegistrationId() {
return registrationId;
}
public void setRegistrationId(String registrationId) {
this.registrationId = registrationId;
}
public boolean equals(Object obj) {
return ReflectionUtil.compareObjects(this, obj);
}
public String getExternalID() {
return externalID;
}
public void setExternalID(String externalID) {
this.externalID = externalID;
}
public double getOpeningBalance() {
return openingBalance;
}
public void setOpeningBalance(double openingBalance) {
this.openingBalance = openingBalance;
}
public double getClosingBalance() {
return closingBalance;
}
public void setClosingBalance(double closingBalance) {
this.closingBalance = closingBalance;
}
public String toString()
{
return StringUtil.objectToString(this).concat(super.toString());
}
public String getPANNumber() {
return PANNumber;
}
public void setPANNumber(String pANNumber) {
PANNumber = pANNumber;
}
public boolean getIsActive() {
return isActive;
}
public void setIsActive(boolean isActive) {
this.isActive = isActive;
}
public int getTempInt() {
return tempInt;
}
public void setTempInt(int tempInt) {
this.tempInt = tempInt;
}
public int getTempTyniInt() {
return tempTyniInt;
}
public void setTempTyniInt(byte tempTyniInt) {
this.tempTyniInt = tempTyniInt;
}
public boolean getTempBol() {
return tempBol;
}
public void setTempBol(boolean tempBol) {
this.tempBol = tempBol;
}新列(字段)为- temp、tempInt、tempTyniInt、tempBol。
FYI -在升级之后,我们将所有表的DB排序规则从latin1_swedish_ci更改为utf8mb4_unicode_ci & charset从latin1更改为utf8mb4
发布于 2022-05-17 10:01:44
从源- 中找到解决方案
有人评论说-
在MySQLDriver5.x和8.x中,属性nullCatalogMeansCurrent的默认值已经更改。在5.x中,默认值为true,在8.x为false,因此在5.x中,DatabaseMetaData.getTables将准确地从‘example1 1’返回表,而在8.x DatabaseMetaData.getTables中,不仅返回'example1',而且返回所有数据库中的表,这就是为什么SQL将更改为'INSERT (姓氏)值(?)‘。解决办法是,在使用MySQL-Driver8.x时,将nullCatalogMeansCurrent=true添加到conn,所有测试都会成功通过。
https://stackoverflow.com/questions/72256184
复制相似问题