users@glassfish.java.net

Re: FetchType.EAGER behaviour

From: <glassfish_at_javadesktop.org>
Date: Fri, 13 Jul 2007 07:26:35 PDT

This is a rather harsh statement for something that could be an object model design issue. Are you certain that you want to do a join 3 or more levels deep each and ever time you execute a simple find on an Entity? Part of the reason 1:M and M:M mapping use lazy by default is to avoid bringing in your entire object tree unneccessarily even on simple find queries.

As Marina mentioned, caching allows TopLink just to return that object if it already exists. So you will get your N+1 queries for eagerly fetched relations on your first read of the entity, but afterward you will get the object from the cache - the joins would not be neccessary. You can avoid some of the load process using fetch join on your initial query, but as mentioned earlier, there is a limit on how deep it can go. If you really need to load each and every one of the 3rd level relations into memory (ie eager), fetch join drops your 30^3 to 30^2.

TopLink Essentials does allow setting mappings to always use joining, but this is configurable through customizers rather than being on by default.

Best Regards,
Chris
[Message sent by forum member 'chris_delahunt' (chris_delahunt)]

http://forums.java.net/jive/thread.jspa?messageID=226575