An entity has a HashMap as property, property is convertered using an AttributeConverter.
After updating the hashmap, the dirty check does not flag this property as dirty and no update is done.
{noformat}@Entity @Table(name = "person") public class Person { @Id private int id; ... @Convert(converter = HashMapConverter.class) private Map<String, Object> attributes = new HashMap<>(); ... }
public class HashMapConverter implements AttributeConverter<HashMap<String, Object>, String> {
private final ObjectMapper mapper = new ObjectMapper();
@Override public String convertToDatabaseColumn(HashMap<String, Object> stringObjectHashMap) { try { return mapper.writeValueAsString(stringObjectHashMap); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
@Override public HashMap<String, Object> convertToEntityAttribute(String string) { try { return mapper.readValue(string, new TypeReference<>() {}); } catch (IOException e) { throw new RuntimeException(e); } } }{noformat}
*test case* is here: [github|https://github.com/BartVansegbroeck/hhh16105]
I’ve added a failing test case in orm/hibernate-orm-6
and a working test case with the same setup in orm/hibernate-orm-5
test case: [github|https://github.com/BartVansegbroeck/hhh16105] |
|