quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.

Home Page:https://quarkus.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hibernate data loss bug: Hibernate can null out a row in some circumstances

stuartwdouglas opened this issue · 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.

Thanks Stuart. I suspect this is a duplicate of the one @dreab8 is working on. @dreab8 could you check and confirm?

Hi @Sanne , checked and It looks the same issue I worked on.