Do you find or refresh after persist or merge, just to use lazy loading?

How many other users have experienced lazy loading being unavailable, immediately after persist or merge, for lazy *ToOne and *ToMany associations?

How many of you use a flush, refresh, find or query, just so you can traverse or initialize more of the object graph, starting from the entity object that you just persisted or merged?

Hibernate is not consistent when returning objects from persist and merge, when compared to those returned from refresh, find and queries, with respect to lazy loaded association properties. This has been the behavior of Hibernate since the beginning, but in our case, this has recently caused serious compatibility issues in our upgrade to Hibernate Search 6.

We have forked Hibernate ORM to resolve the issue, and would like to gather support for the change to be integrated into the main code branch if enough users would appreciate the enhancement.

The goal of the change was to make consistent the lazy loading functionality of entity objects returned from persist and merge, as compared with those returned from find and refresh.

We frequently merge detached entities, which themselves have references to detached entities, because the object graph has been serialized and deserialized (left the session and came back).

If you merge a detach entity, and that entity is indexed, your embedded indexes will fall out of sync with the database, and full text searches will start returning incorrect results after upgrading to Hibernate Search 6. In this release, a major change was made to the timing of indexing in Hibernate Search 6. Indexing now happens at flush time, rather than much later during the commit of the transaction. Therefore, a refresh after persist or merge will no longer have the positive effect on indexing lazy loaded properties that it has had for many years.

Please chime in if you would like proxies automatically installed in your *ToOne and *ToMany association properties by the ORM framework after a persist or merge, so you (or Hibernate Search) can walk the object graph freely and initialize data as needed.

Thank you!