Cannot retrieve Map object with empty entry

(Yeonghowtan) #1

Hi all,

class Cat {
    @Id @GeneratedValue private Long id;
    @Properties(prefix = "property", allowCast = true) private Map<String, Object> property;
}

Cat cat = new Cat();
Map<String, Object> map = new HashMap<>();
map.put("dummy", new HashMap<>());
cat.setProperty(map);
cat = catRepository.save(cat);
System.out.print(cat.getProperty().get("dummy")) // it is {}

// when I do this
Cat newCat = catRepository.findById(cat.getId());
System.out.print(newCat.getProperty().get("dummy")) // it is null

Why is it so?

0 Likes

(Michael Hunger) #2

Dynamic properties only work for one level, not nested documents.

It only works by accident in the first case.

0 Likes