• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question on Lazy Loading?

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

Can anyone please help me on Lazy Loading in Hibernate? Given the following example,

public class User {
int userId;
String username;
EmailAddress emailAddress;
Set roles;
}

The Beginning Hibernate book says "when an instance of the User class given in the next listing is loaded from the database, the only fields initialized will be userId and username." How do they say this? Do they mean to say that only primitives are loaded in the memory first and the Objects are loaded only when they are needed?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No (after all, a String is not a primitive). userId and username are properties of the object you are loading so they are populated. emailAddress and roles are associated objects (i.e. related entities) so the yare not populated until they are asked for.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it. Thanks for the help!
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!