As you guys probably know, I have been doing a lot of thinking about how to orthogonalize the notion of eager/lazy from the notion of fetch strategy (the actual SQL). And I want to do this in a way which allows a good implementation of EJB3 fetching contract, and remains reasonably compatible with what we have today. Oh, and I want to also try and reduce the number of newbie forum posts.

 

The basic concept is that association mappings have both:

 

  • fetch attribute
  • lazy attribute

 

For single-valued associations:

 

  • fetch = “select|join”
  • lazy = “true|false|proxy”

 

where lazy = “true” means use instvar interception, and lazy = “proxy” means use the proxy of the associated class (if it has one).

 

For collection-valued associations:

 

  • fetch = “select|join|subselect”
  • lazy = “true|false”

 

where lazy = “true” is the usual lazy collection fetching we know and love (or hate).

 

For the second join of a many-to-many

 

  • fetch = “select|join”
  • lazy = “false|proxy”

 

Note that this is a special case, since fetch = “join” is the default!

 

So, here are the new rules:

 

(1)   if lazy is specified, use the specified laziness semantics

(2)   if lazy is not specified and fetch = “join”, assume lazy = “false”

(3)   if lazy is not specified and not fetch = “join”

a.      for collections, assume the default-lazy (almost always “true”)

b.      for single-valued associations, assume “proxy”

 

Only rule (2) is suspect. We don’t need it, and I can get rid of it if you guys like. I’ve added it because I think it might help reduce the number of forum questions from people who wonder “why do I get lazy fetching when fetch=join?”.

 

Note that the association-level lazy setting is now *completely respected*. if I run a HQL query and some of the objects in the result set have non-lazy associations, those associations will be *immediately fetched*.

 

 

Reply via email to