How to set the id on detached Hibernate proxy without LazyInitializationException? -
i'm using object, has on 15 related entities (parents). in ui side need ids of these entities, don't need hibernate's fetch functionality , use lazy proxy concept avoid hit database on 1 hand , have objects populated ids on other.
to achieve have use property acces instead of field access parent entities:
@id @access(accesstype.property) // helps avoid database hit on get, not on set!!! private long id;
so far good, load object database (no joins made) , show on web ui relations (simple select inputs @ most). don't create clones (value objects) ui, use detached hibernate objects directly. when changes ui (change parent object) framework calls setid() related proxy entities , .... results in initialization of these proxies! here code hibernate basiclazyinitializer this:
else if ( method.equals(setidentifiermethod) ) { initialize(); // here db hit occurs!! setidentifier( (serializable) args[0] ); return invoke_implementation; }
and lazyinitializationexception occurs (sure, have no session @ point of time!).
so, there approach without creation of value objects entities, fetched database? can say, used data objects in ui directly, fetched (not proxies) , haven't had such problems these proxies...
i don't understand, why hibernate makes proxy initialization on setting (though doesn't on getting) @id field...
thanks in advance!
Comments
Post a Comment