Reputation: 2365
I am using spring boot 2.4.1
with spring-boot-starter-data-cassandra
.
Here is the Repository class
@Repository
public interface UserRepository extends CassandraRepository<UserModel, String> {
}
Below is the POJO
@Table("user")
public class UserModel {
@PrimaryKeyColumn(name = "userid", type = PrimaryKeyType.PARTITIONED)
private String userId;
@Column("emailid")
private String emailId;
@Column("phonenumber")
private String phoneNumber;
//getters and setters
}
Here is the class calling update method :
@Component
public class UpdateTask {
@Autowired
private UserRepository userRepository;
public void removePhoneNumber(UserModel t) {
t.setPhoneNumber(null);
userRepository.save(t);
}
}
Problem is I want to update the phone number field to null
as user wants to remove their phone number. But cassandra ignores the null value set. How to explicitly set a value to null in cassandra ?
Upvotes: 0
Views: 483
Reputation: 48
It might be done with the DELETE cql command -If an INSERT statement only specifies NULL values for a column or does not specify any values for a column, then the driver omits that column when executing the INSERT statement you can refer to this https://issues.apache.org/jira/browse/CASSANDRA-3783
Upvotes: -2
Reputation: 246
Try this one:
public void removePhoneNumber(UserModel t) {
UserModel userModelToUpdate = userRepository.getOne(t.userId);
userModelToUpdate.setPhoneNumber(null);
userRepository.save(userModelToUpdate);
}
Upvotes: -2