Search code examples
hibernatenhibernatenhibernate-mappinghibernate-mapping

Nhibernate how to get rid of proxies and have the concrete when reference is loaded


I have Item with 1:m relation to TreeNode. TreeNode has refernce to parent node ... and has reference to another Objects.

TreeNode and his relation are stored in second level cache.

My problem: If i use the default lazy than these TreeNode will be loaded from second level cache if i travel on the parent.

But It will be loaded as a proxy and i have to have it as concrete class (i call to function on this Object and association more than 2000 times).

If i set lazy=false on the TreeNode class def: Than hibernate will load all the reference of its in the join and i will not have benefit from the second level cache.

Can i define that object will be loaded as concrete andassociation of it when loaded (by call the association) also will be loaded as concrete?

Thank you


Solution

  • if you dont want a proxy put lazy=false on the class level or crate a clone on the object.