Fetching an already loaded entity with an EntityGraph does not initialize previously lazy loaded attributes

Description

None

Environment

None

Activity

Show:
Réda Housni Alaoui
December 23, 2015, 9:58 PM

Hello Veit,

I know this method but it is not a solution for us for performance reasons.

Cloves Almeida
October 24, 2016, 1:30 PM

This is a major blocker for using 2nd-level cache. In a lot of places we need to work on detached objects and rely on the the attributes being loaded.

Steve Ebersole
December 15, 2017, 8:52 PM

This is super low priority for me personally right now. I can see doing this as part of 6.x. If its critical for someone earlier, your best bet is to provide a PR.

Réda Housni Alaoui
December 16, 2017, 12:10 PM
Edited

I have 2 fixes in mind.

Load the proxies individually

Visit the provided EntityGraph and initialize each concerned entity linked proxy individually before returning the entity.

Refetch the entity

If an entity graph is provided, remove the entity from the cache before refetching it from the database.
If we knew what EntityGraph was used to load the entity first, we could dump the entity from the cache only if the provided graphs is wider.

, would you accept any of this fix? If not, could you give me a hint?

Steve Ebersole
December 16, 2017, 4:06 PM

If an entity graph is provided, remove the entity from the cache before refetching it from the database.

This will not work.

While I have ideas how to address this in 6 based on some of the changes we are making there, you want a solution for 5... Your first option certainly works. A tweak to your second option works as well - simply do not drop it from the Session cache; take the incoming graph and use it to build and execute the query - Hibernate already has the logic to know to skip reading a particular entity from the ResultSet because it exists in the Session.

The concern is which to choose. Each have pretty big performance drawbacks when used in the wrong scenario and unfortunately which to use depends on information we do not readily have - mainly how much of the requested graph needs to be loaded.

Assignee

Unassigned

Reporter

Réda Housni Alaoui

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

Affirmative

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure