h2. What Happened
Version: spring boot {{3.0.2}} with Hibernate {{6.1. 7 6 .Final}}.
With the following simple entity, if we simply put another field to its {{properties}} field, the entity won’t be saved.
{code:java}@Table @Entity public class MetaEntry {
@Id private String uuid;
@Convert(converter = PropertyConverter.class) private Map<String, Object> properties;
private String str = "x"; // ... }{code}
* 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.
{code:java}@Component public class TestService {
private final MetaRepository metaRepository;
@Autowired public TestService(MetaRepository metaRepository) { this.metaRepository = metaRepository; }
@Transactional // will work if commented public void patchProperties(String uuid, String key, Object value) { var meta = metaRepository.findById(uuid).get(); meta.getProperties().put(key, value); // meta.setStr(key); // will work if uncommented metaRepository.save(meta); } }{code}
Expected Behavior: The entity will be saved under {{@Transactional}} annotation and if only the {{properties}} gets modified.
h2. 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}}.
h2. Test Case
Run {{mvn test}} after extract the attached file. The test {{JpaTest1ApplicationTests#test}} will reproduce the issue.
Thanks! |
|