Reputation: 11975
I am new to Spring Data Redis and trying to save the deletedDate
as null. When I am persisting deletedDate
in Redis, its not persisting null. I am using Java8 LocalDateTime
formatter.
User.java
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@RedisHash("users")
public class User {
@Id @Indexed
private String userId;
private String name;
private LocalDate createdDate;
}
MyTestclasses:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class UserGroupTest extends RepositoryTestSupport{
@Autowired private UserRepository userRepository;
@Autowired private GroupRepository groupRepository;
@Autowired private UserGroupRelRepository userGroupRelRepository;
@Before
public void setUp() throws JsonProcessingException {
User raj = User.builder().name("Raj Kumar").createdDate(null).build();
User parag = User.builder().name("Parag Rane").createdDate(null).build();
User sagar = User.builder().name("Sagar Parate").createdDate(null).build();
userRepository.saveAll(Arrays.asList(raj, parag, sagar));
Group hardware = Group.builder().name("Hardware").build();
Group software = Group.builder().name("Hardware").build();
Group machineLearning = Group.builder().name("Mchine Learning").build();
Group ai = Group.builder().name("Artificial Inteligence").build();
groupRepository.saveAll(Arrays.asList(hardware, software, machineLearning));
// Raj interested in Hardware and AI
UserGroupRel userGroupRel1 = UserGroupRel.builder().userId(raj.getUserId()).groupId(hardware.getGroupId()).build();
UserGroupRel userGroupRel2 = UserGroupRel.builder().userId(raj.getUserId()).groupId(ai.getGroupId()).build();
// Parag interested in hardware, software and ML
UserGroupRel userGroupRel_1 = UserGroupRel.builder().userId(parag.getUserId()).groupId(hardware.getGroupId()).build();
UserGroupRel userGroupRel_2 = UserGroupRel.builder().userId(parag.getUserId()).groupId(software.getGroupId()).build();
UserGroupRel userGroupRel_3 = UserGroupRel.builder().userId(parag.getUserId()).groupId(machineLearning.getGroupId()).build();
// Sagar intersted in AI and ML
UserGroupRel user_GroupRel1 = UserGroupRel.builder().userId(sagar.getUserId()).groupId(machineLearning.getGroupId()).build();
UserGroupRel user_GroupRel2 = UserGroupRel.builder().userId(sagar.getUserId()).groupId(ai.getGroupId()).build();
userGroupRelRepository.saveAll(Arrays.asList(userGroupRel1, userGroupRel2, userGroupRel_1, userGroupRel_2,
userGroupRel_3, user_GroupRel1, user_GroupRel2));
List<UserGroupRel> userGroupRels = userGroupRelRepository.findByGroupId(hardware.getGroupId());
System.out.println("USER GROUPS DETAILS SIZE :"+userGroupRels.size());
for (UserGroupRel userGroupRel : userGroupRels) {
System.out.println("USER_GROUP :"+new ObjectMapper().writeValueAsString(userGroupRel));
List<User> users = userRepository.getByUserId(userGroupRel.getUserId());
for(User u : users) {
System.out.println("Users interested in Hardwares are : "+u.getName());
}
}
}
}
Question has been posted here: https://jira.spring.io/browse/DATAREDIS-912
I saw https://github.com/facebook/hhvm/issues/6062 & https://github.com/NodeRedis/node_redis/issues/507, but things are not clear as far as implementing in Spring Data Redis.
Upvotes: 0
Views: 836
Reputation: 18119
Spring Data Redis Repositories represent properties with null
values as non-written hash entries. Or simplified: null
properties are not written to Redis.
Upvotes: 1