Reattaching entity with one-to-many lazy list mapped collection can update index column

Description

Repro steps:

  • Have an Entity with a lazy loaded list

  • Load the Entity in a transaction and initialize the list

  • Close transaction and save the reference to detached object

  • Merge the object in a new transaction and do not touch the collection

  • OrderColumn will be updated after commit of second transaction

I belive the problem is in OneToManyPersister and org.hibernate.collection.internal.PersistentList.Clear (Persister seems to shift items when a clear operation is queued)

Environment

Java 1.8.66
Windows 8 64
PostgreSQL 9.2

Activity

Show:
Ivan Korhner
May 15, 2016, 6:38 PM

Since I am new here and did not contribute to hibernate projects before, it would be great if somebody could confirm that this is not an expected behavior and if it is, I can investigate this further and confirm the cause of the problem.

Nathan Xu
December 21, 2019, 12:31 PM

I checked your code locally. An interesting testing case and I spent lots of time figuring out why the result is different between running and debugging mode in IDE. Still figuring out why.

However, I found you are using merge to reattach a detached entity. It seems update is more appropriate in that scenario and when I substitute its usage I found no error shows up and everything is working as expected.

Maybe merge to reattach a detached entity should behave the same way in that the index should not change? That is an interesting question and I would love to dig deeper. Anyway, a good bug reporting and thanks from a community contributor.

Nathan Xu
December 21, 2019, 12:32 PM

Given that update is more appropriate and it is working fine, I think we can lower the severity of this ticket for you are exploring the limit, not the canonical feature.

Assignee

Unassigned

Reporter

Ivan Korhner

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Blocker
Configure