fix 校验Property是否为空,解决将序列化当作字段bug

This commit is contained in:
cxc 2024-12-19 09:15:09 +08:00
parent 51cc4ed9df
commit 4c17b0a003
2 changed files with 14 additions and 4 deletions

View File

@ -114,7 +114,9 @@ public class LambdaInsertWrapper<T> extends AbstractChainWrapper<T> implements
String key = entry.getKey(); String key = entry.getKey();
Object value = entry.getValue(); Object value = entry.getValue();
String tk = propertyCache.functionToPropertyMap.get(key); String tk = propertyCache.functionToPropertyMap.get(key);
GsonUtil.put(jsonObject,tk,value); if (StringUtils.isNotEmpty(tk)) {
GsonUtil.put(jsonObject,tk,value);
}
} }
if(conversionCache.isAutoID()){ if(conversionCache.isAutoID()){
GsonUtil.put(jsonObject,pk,IdWorkerUtils.nextId()); GsonUtil.put(jsonObject,pk,IdWorkerUtils.nextId());

View File

@ -676,6 +676,9 @@ public class LambdaUpdateWrapper<T> extends AbstractChainWrapper<T> implements W
public MilvusResp<UpsertResp> update(T entity) throws MilvusException { public MilvusResp<UpsertResp> update(T entity) throws MilvusException {
// 获取主键字段 // 获取主键字段
String primaryKeyField = CollectionToPrimaryCache.collectionToPrimary.get(collectionName); String primaryKeyField = CollectionToPrimaryCache.collectionToPrimary.get(collectionName);
if (StringUtils.isNotEmpty(primaryKeyField)) {
throw new MilvusException("not find primary key", 400);
}
// 将实体转换为属性映射 // 将实体转换为属性映射
Map<String, Object> propertiesMap = getPropertiesMap(entity); Map<String, Object> propertiesMap = getPropertiesMap(entity);
PropertyCache propertyCache = conversionCache.getPropertyCache(); PropertyCache propertyCache = conversionCache.getPropertyCache();
@ -695,8 +698,11 @@ public class LambdaUpdateWrapper<T> extends AbstractChainWrapper<T> implements W
hasPrimaryKey = true; hasPrimaryKey = true;
primaryKeyValue = value; primaryKeyValue = value;
} }
// 添加到更新对象 // 校验是否为空
GsonUtil.put(updateObject,tableNameColumn, value); if (StringUtils.isNotEmpty(tableNameColumn)) {
// 添加到更新对象
GsonUtil.put(updateObject,tableNameColumn, value);
}
} }
// 检查是否需要构建查询条件 // 检查是否需要构建查询条件
boolean needBuildQuery = !hasPrimaryKey; boolean needBuildQuery = !hasPrimaryKey;
@ -783,7 +789,9 @@ public class LambdaUpdateWrapper<T> extends AbstractChainWrapper<T> implements W
Object value = entry.getValue(); Object value = entry.getValue();
// 根据PropertyCache转换属性名 // 根据PropertyCache转换属性名
String tk = propertyCache.functionToPropertyMap.get(key); String tk = propertyCache.functionToPropertyMap.get(key);
GsonUtil.put(jsonObject,tk, value); if (StringUtils.isNotEmpty(tk)) {
GsonUtil.put(jsonObject,tk, value);
}
} }
// 检查是否包含主键 // 检查是否包含主键
if (!jsonObject.has(pk)) { if (!jsonObject.has(pk)) {