Hibernate data loss bug: Hibernate can null out a row in some circumstances
stuartwdouglas opened this issue · 3 comments
Hibernate can attempt to write unloaded proxy state to the database in some circumstances, effectively 'nulling out' a row. This can happen in transactions that are otherwise read only.
Reproducer is here:
master...stuartwdouglas:hibernate-data-loss
Basically if you:
- Initialize a collection field with an empty collection
- And have a date field (or other mutable property)
- Create a proxy for the entity but don't actually load it
Hibernate will get confused, and will write out the unitialized state.
I am not 100% sure how this is supposed to work, but it seems like SimpleCollectionTracker is not initialized with the names and sizes, which makes it return -1 which triggers a full dirty check. As the proxy is not loaded in the mutable property check in org.hibernate.persister.entity.AbstractEntityPersister#resolveDirtyAttributeIndexes will think the date has been modified as previousState == null. This causes hibernate to write out empty data into the DB.