Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lazy Load in Entity Beans Relationship

 
Flavio Nobili
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way of saying to the container that I want a "lazy load" of entity beans in a relationship (like I can do in Hibernate)?

Tanks
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Entity Beans naturally are "lazy loaders". A CMR field holds a reference to a local component interface or a collection of local interfaces. The (related) entity itself is only loaded by the container once you invoke a business method through that local interface.

I anything, a vendor extension (not the spec) may allow you to specify eager-loads of entities that you will most likely need - as long as you can guarantee that the EJB Server is total control of that portion of the underlying persistent store - so that it doesn't waste time on unnecessary ejbLoads().
 
Mihai Alexe
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, most application servers allow you to influence the loading strategy for entity beans that participate in relationships (via their local business interfaces). You can have lazy-loading (my guess this is a natural default, since it usually provides optimal performance when dealing with multiple relationships), and eager-loading . With eager-loading, use it as "full" (i.e. when a bean gets loaded, load all beans that participate in a relationship with the first bean, even indirectly) with caution, since it can easily generate a whole bunch of ejbLoad() calls and unnecessary bean instances (especially when we�re dealing with many-to-many or many-to-one relationships). Of course, the lazy-loading tradeoff is more computation during bean access. It is up to you to dig in the AS documentation and see what can and what can not be done and decide your strategy. Just remember that loading strategies and a number of other optimizations are beyond (i.e. not specified) in the ejb specification. That leaves room for the AS vendors to optimize and make us AS users happier (at least in theory)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic