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. |