• Post Reply Bookmark Topic Watch Topic
  • New Topic

Any reason for Lazy Exception  RSS feed

 
Ryan Raina
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Consider the following code





My main method


}

I am getting this exception on System.out.println(user2.getUserName())




It looks like session was closed that's why it happened
But isn't this applicable to the collections only...here I have a simple property which I am fetching which should be fetched eagerly by default

Thanks in advance
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
 
Ryan Raina
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hebert Coelho wrote:This posts talk about the problem and give 4 solutions: http://uaihebert.com/?p=1383


I am still not able to understand it ..only collection should be LAZY fetch but a simple property should be eager by default...
 
Ryan Raina
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan Raina wrote:
Hebert Coelho wrote:This posts talk about the problem and give 4 solutions: http://uaihebert.com/?p=1383


I am still not able to understand it ..only collection should be LAZY fetch but a simple property should be eager by default...


I think I have figured this out ..The problem is with load method which always returns a proxy whether for simple property or collection...But if one uses get method it eager fetches simple properties but still gives a proxy for all collections...
Also if ID is not found get will return null while as load will throw an exception..


Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!