java - Does hibernate load two seprate copies of same instance if they are loaded twice from database? -


i know there many different question on regarding lazy load mine 1 bit different.

lets have entity in have collection of entity b. similarly, in entity b, have collection of a. in both case, lazy="true" option used.

entity a's instace aa has -->set<b>===(this set contains entity b's instance bb)

entity b's instace bb has -->set<a>===(this set contains entity a's instance aa)

now if load entity a's collection(which set<b> ).its initialized now, i.e. complete a's aa instance including collection. expect entity b's instance bb initialized no, not , lazy initialization exception when refer entity b's collection has entity a's instance aa.

does hibernate load 2 seprate copies of same instance if loaded twice database? if so, there way synchronize changes in copies within session?

hope clear enough , haven't messed things messy info:)

the flow this:

  1. you load aa , ab. collections lazy , proxied.
  2. you initialize aa's collection. among others, contains instance ab , same 1 loaded before (the same java object). collection in ab instance is still uninitialized; didn't access it, hibernate doesn't waste time initialize it. @ time, unknown in session aa member of ab's collection.
  3. you access (initialize) ab's collection. among others, contains instance aa , same 1 loaded before (the same java object).

as can see, there no duplicates in current session (persistence context). there may different proxies/collections, delegate to/contain same entity instance.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -