Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
stuartwdouglas opened this issue Feb 7, 2021 · 3 comments · Fixed by #14907
Closed

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

stuartwdouglas opened this issue Feb 7, 2021 · 3 comments · Fixed by #14907
Labels
area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE kind/bug Something isn't working
Milestone

Comments

@stuartwdouglas
Copy link
Member

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.

@stuartwdouglas stuartwdouglas added kind/bug Something isn't working area/hibernate-orm Hibernate ORM labels Feb 7, 2021
@ghost ghost added the area/persistence OBSOLETE, DO NOT USE label Feb 7, 2021
@ghost
Copy link

ghost commented Feb 7, 2021

/cc @Sanne, @gsmet, @yrodiere

@Sanne
Copy link
Member

Sanne commented Feb 7, 2021

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

@dreab8
Copy link
Contributor

dreab8 commented Feb 8, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants