2016-08-17 99 views
2

使用Spring Boot,Cassandra,org.springframework.data.repository.CrudRepository保存实体。在Spring中使用CrudRepositoty保存具有NULL值的实体

我有下一个实体:

@Table("user") 
public class User implements Serializable { 
    @PrimaryKey 
    private UUID id; 
    private String name; 
... 
} 

库:

public interface UserRepository extends CrudRepository<User, UUID> {} 

保存实体:

user.setName(null); 
userRepository.save(user); 

CrudRepository不写与NULL值属性数据库,因为

if (value != null) { 
        log.debug(String.format("Adding insert.value [%s] - [%s]", prop.getColumnName().toCql(), value)); 
        insert.value(prop.getColumnName().toCql(), value); 
       } 

在MappingCassandraConverter.java

是否有一些方法可以使用CrudRepository保存NULL值?

回答

3

它固定在6月28日。 对以下网址 https://github.com/spring-projects/spring-data-cassandra/pull/72

我们现在允许插入和空值由 MappingCassandraConverter书面Update语句支持与空值 的属性去除柱的外观。对象与所有持久性 属性一起存储。插入和更新不再有条件插入非空值的 ,但要考虑所有值。

目前的版本是

<version>1.4.2.RELEASE</version> 

但是我认为这种改变是在

<version>1.5.0.BUILD-SNAPSHOT</version> 

您可以等待下一个官方发布,或者你可以去这个网址 http://projects.spring.io/spring-data-cassandra/#quick-start 并在下载选择旁边的下拉菜单中选择,而不是1.4.2 1.5.0快照。如果系统在生产中,我会建议您等待下一次正式发布。

希望这有助于

+0

我正在使用** 1.5.3.RELEASE **,但问题仍然存在。 \t \t \t \t如果(值== NULL){ \t \t \t \t \t回报; \t \t \t \t} \t \t \t \t如果(日志。isDebugEnabled()){ \t \t \t \t \t log.debug( “添加insert.value [{}] - [{}]”,property.getColumnName()toCql(),值)。 \t \t \t \t} – Daniel

1

我使用1.5.3.RELEASE,但问题依然存在。

if (value == null) { 
    return; 
} 

if (log.isDebugEnabled()) { 
    log.debug("Adding insert.value [{}] - [{}]", property.getColumnName().toCql(), value); 
}   
相关问题