SimpleJdbcInsert 在 MySQL 中混合来自不同数据库的列名
SimpleJdbcInsert mixes column names from different databases in MySQL
我最近将 spring 框架从 5.0.3 升级到 5.3.12,mysql 从 5.7 升级到 8。
我正在数据库中添加新列并在模型中添加相应字段 class。但它无法在数据库中存储新添加字段的值。我已经调试了程序,值在模型 class 中进行了修补,但是在调用 simplejdbcinsert api 之后,值不会在数据库中持续存在。
代码是这样的-
DAO 调用 -
logger.debug("Party Insert: " + logStr);
ID = new SimpleJdbcInsert(dataSource).withTableName("TBL_PARTY")
.usingGeneratedKeyColumns("Id").executeAndReturnKey(sqlParams).intValue();
型号class-
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。
仅供参考 - 升级后,我们已将所有表的数据库排序规则从 latin1_swedish_ci
更改为 utf8mb4_unicode_ci
,字符集从 latin1
更改为 utf8mb4
从源头找到了解决方案-
https://github.com/spring-projects/spring-framework/issues/22015
有人评论了 -
属性 nullCatalogMeansCurrent 的默认值已在 mysql-driver 5.x 和 8.x 中更改。在5.x中默认值为true,在8.x中默认值为false,所以在5.x中DatabaseMetaData.getTables会return完全来自 'example1' 和 8.x DatabaseMetaData.getTables 的表格将 return 表格不仅来自 'example1',而且来自所有数据库,这就是 SQL 将更改为 'INSERT INTO persons (lastname) VALUES (?)' 的原因。
解决方法,在使用 mysql-driver 8.x 时将 nullCatalogMeansCurrent=true 添加到 conn url,所有测试都成功通过。
我最近将 spring 框架从 5.0.3 升级到 5.3.12,mysql 从 5.7 升级到 8。
我正在数据库中添加新列并在模型中添加相应字段 class。但它无法在数据库中存储新添加字段的值。我已经调试了程序,值在模型 class 中进行了修补,但是在调用 simplejdbcinsert api 之后,值不会在数据库中持续存在。
代码是这样的-
DAO 调用 -
logger.debug("Party Insert: " + logStr);
ID = new SimpleJdbcInsert(dataSource).withTableName("TBL_PARTY")
.usingGeneratedKeyColumns("Id").executeAndReturnKey(sqlParams).intValue();
型号class-
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。
仅供参考 - 升级后,我们已将所有表的数据库排序规则从 latin1_swedish_ci
更改为 utf8mb4_unicode_ci
,字符集从 latin1
更改为 utf8mb4
从源头找到了解决方案- https://github.com/spring-projects/spring-framework/issues/22015
有人评论了 -
属性 nullCatalogMeansCurrent 的默认值已在 mysql-driver 5.x 和 8.x 中更改。在5.x中默认值为true,在8.x中默认值为false,所以在5.x中DatabaseMetaData.getTables会return完全来自 'example1' 和 8.x DatabaseMetaData.getTables 的表格将 return 表格不仅来自 'example1',而且来自所有数据库,这就是 SQL 将更改为 'INSERT INTO persons (lastname) VALUES (?)' 的原因。 解决方法,在使用 mysql-driver 8.x 时将 nullCatalogMeansCurrent=true 添加到 conn url,所有测试都成功通过。