Hello, welcome everybody this is my first post on the forum, so if I do something wrong, don't kill me ;)
I have little proposal for lazy loading:
Suppose I have entity @Entity Public class Boss { private Long id; private @ManyToOne() Company company; } and I try to load Boss entity by primary key form DB: Sesion s = …; Boss boss = s.get(Boss.class, 1l); //get by pk When I try to get company’s id, as I understand, the proxy will load FULL Company entity, not only ID that I only wanted. Boss.getCompanty().getId(); Company’s id is in the same table as Boss, and it has been loaded into memory, lazy loading needs to know what to load when user call getCompany(). Lazy loading should load full entity only when I try to get other field than PK, not the entity itself (not boss.getCompany() ) . So if I call: Boss boss = s.get(Boss.class, 1l); the empty Company entity should be filled with PK field, when I want to access any other field, the layzy loading should then load the full entity.
It can be accomplished through HQL, should maybe it could be done through API. Any comments?
|