java - What is the name (or keywords) of methodology/technique to hold ids instead of related entities in entity? -
entity hold data mapped data persistent storage. db.
you can hold ids:
class book { private string title; public string gettitleid() { return title; } private long publisherid; // <== **it is**! public long getpublisherid() { return publisherid; } private list<long> authorids; public list<long> getauthorids() { return authorids; } }
or resolved entities:
class book { private string title; public string gettitleid() { return title; } private publisher publisher; // <== **it is**! public publisher getpublisher() { return publisher; } private list<author> authors; public list<author> getauthors() { return authors; } }
if use orm hibernate working resolved entities simple orm *join*s related entities free.
but if concern on performance or want use db features move logic java sql manual sql queries entities ids win (they faster , annoying join each related entities manually)!
so decide maintain 2 type of entities: ids , resolved related entities hold knowledge in data type (in type name).
so start googling best suffixes class names can't find appropriated keywords. please tell me how name of methodology/tecnichue hold ids vs related entities in entity!
i think terms looking
eager versus lazy loading , fetching strategies.
see
edit:
the lazy-loaded entity can referred proxy, not-yet-initialized collection wrapper.
in reaction comments: see hibernate one-to-one: getid() without fetching entire object. hibernate can produce id values lazy loaded entities.
from hibernate faq:
how can retrieve identifier of associated object, without fetching association?
just it. following code not result in select statement, if item association lazy.
long itemid = bid.getitem().getid();
this works if
getitem()
returns proxy , if mapped identifier property regular accessor methods. if enabled direct field access id of item, item proxy initialized if callgetid()
. method treated other business method of proxy, initialization required if called.
Comments
Post a Comment