What Happened Version: spring boot 3.0.2 with Hibernate 6.1.7.Final. With the following simple entity, if we simply put another field to its properties field, the entity won’t be saved.
@Table
@Entity
public class MetaEntry {
@Id
private String uuid;
@Convert(converter = PropertyConverter.class)
private Map<String, Object> properties;
private String str = "x";
}
- The entity won’t be saved after calling patchProperties function.
- If @Transactional is removed, the entity WILL BE saved.
- If @Transactonal is kept but another field setStr is modified, then the entity WILL BE saved.
@Component
public class TestService {
private final MetaRepository metaRepository;
@Autowired
public TestService(MetaRepository metaRepository) {
this.metaRepository = metaRepository;
}
@Transactional public void patchProperties(String uuid, String key, Object value) {
var meta = metaRepository.findById(uuid).get();
meta.getProperties().put(key, value);
metaRepository.save(meta);
}
}
Expected Behavior: The entity will be saved under @Transactional annotation and if only the properties gets modified. What Else
- I’ve tried the same code with spring boot 2.7.9 with Hibernate 5.6.15.Final and all worked fine.
- I’ve tried to debug the process and found that the loadedState of EntityEntry shares the same HashMap object with user’s meta.getProperties.
Test Case Run mvn test after extract the attached file. The test JpaTest1ApplicationTests#test will reproduce the issue. Thanks! |