users@glassfish.java.net

Re: How to enable Eager Loading for OneToOne and ManyToOne entity relationships

From: <glassfish_at_javadesktop.org>
Date: Mon, 12 May 2008 13:01:04 PDT

Hello,

I'm not sure if your test can really tell B was fetched eagerly or not. TopLink Essentials will use a L2 cache by default, so if A was previously accessed, and the relation previously triggered, then B would appear as if it was eagerly fetched later on.

A better test might be to read A using a find, then refresh A. This will cause TopLink to rebuild/reset the A->B relationship. If the relation is set to cascade refresh, you will then see a database hit when the A-B relationship is first accessed if it is lazy, or right away if it is eager. SQL queries to the database will show in the logs if you turn on the TopLink log level to finest.

If this is a J2EE application, you will need to be sure to use the agent to weave classes, allowing lazy access for 1:1s and M:1 relations. This is described at:
  http://weblogs.java.net/blog/cayhorstmann/archive/2006/06/the_innermost_s.html
If it is container managed (for instance getting the EM from within glassfish) the agent shouldn't be needed.

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

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