Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Object Relational Mapping and the fly likes Any reason for Lazy Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Any reason for Lazy Exception" Watch "Any reason for Lazy Exception" New topic
Author

Any reason for Lazy Exception

Ryan Raina
Greenhorn

Joined: Jun 16, 2010
Posts: 28
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

Joined: Jul 14, 2010
Posts: 754

This posts talk about the problem and give 4 solutions: http://uaihebert.com/?p=1383


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Ryan Raina
Greenhorn

Joined: Jun 16, 2010
Posts: 28
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

Joined: Jun 16, 2010
Posts: 28
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
 
Consider Paul's rocket mass heater.
 
subject: Any reason for Lazy Exception