-
1. Re: When to use EAGER / LAZY
instinct Mar 3, 2006 2:13 AM (in response to gus888)Did you call getFiles() in your Session Bean before calling the method on the entity in the client?
-
2. Re: When to use EAGER / LAZY
ppc Mar 3, 2006 2:29 AM (in response to gus888)if you are using the remote interface when the bean is serialized the field files is null and jboss does not initialize the field because you ask to be lazy, peraphs if you client lives in the container using @local interface the things must work
-
3. Re: When to use EAGER / LAZY
gus888 Mar 3, 2006 11:01 AM (in response to gus888)Thank you all for your response. What I did is:
First, I use JSF session bean to call local interface of dao stateless bean to get a folder instance using a EJBQL, then call the folder.getFiles() in the JSF session bean to try to get all files under the folder. If I set fetch=FetchType.LAZY, I would get exception shown above. If I set fetch=FetchType.EAGER, it will work. I do not know why I got the exception on the LAZY. Thanks for your help. -
4. Re: When to use EAGER / LAZY
nholbrook Mar 3, 2006 1:42 PM (in response to gus888)The session is opened and closed inside the stateless bean method. Once the folder object is passed back across the wire, it is no longer connected to the session / datasource and cannot retrieve the files. You might consider writing a getFiles method in your stateless bean and call that instead of the getFiles on your Folder object if you want it to be lazy and detached.
-
5. Re: When to use EAGER / LAZY
gus888 Mar 3, 2006 2:08 PM (in response to gus888)Hi, thank you very much for your response.
"Writing a getFiles method in your stateless bean" means to create another EJBQL to retrieve files using the passed folder object. Is it correct? Thanks. -
6. Re: When to use EAGER / LAZY
nholbrook Mar 3, 2006 3:25 PM (in response to gus888)Either that or make your fetch type eager.
-
7. Re: When to use EAGER / LAZY
gus888 Mar 3, 2006 3:34 PM (in response to gus888)That's great! I got it. Thank you so much.
-
8. Re: When to use EAGER / LAZY
treespace Mar 4, 2006 4:50 PM (in response to gus888)This is a fundamental question of paramount importance to EJB 3.0 entity bean development. EJB 3.0 keeps it simple and loads everything. You can take a different tack and lazy load everything for maximum performance.
When you get an exception such as yours, you can analyze the situation. If that item is accessed with high frequency then mark it as eager. If access to that information is infrequent, mark it as lazy and add a session bean method to explicitly populate those fields from its entity manager.
Having default lazy loading with magical remote loading would be nice but what entity manager would it use? Also, you would then have to remote the business logic that may or may not be applied at load time.
It would be useful if an official WHEN-TO was published for lazy/eager but I think I am on the right track with my comments. Just starting to use EJB 3.0 myself.