2 Replies Latest reply on Apr 7, 2006 8:54 PM by Alexander Hartner

    fetch type eager

    daniel jarrett Newbie

      Hi There,

      I have used fetch type eager in the design of most of my pojos. This has created a problem in that in order to populate or instantiate these objects and subsequent child objects I am doing a large number of sql queries. Are there ways of minimizing these queries or do i just need to rethink they way i am fetching things ?

      Thanks
      DD

        • 1. Re: fetch type eager
          mazz Master

          I believe you will need to rethink the way you are doing things.

          You'll probably want to use LAZY fetching most of the time and utilize EJBQL to eagerly fetch things you know you'll want to fetch.

          This requires you to create session beans (call them DAO's if you want, or call them FooBar Beans, whatever, I won't get into the DAO discussion again :-) and those session beans would provide methods that eagerly load your entities for the use-cases in which you need eager loading (by performing EJBQL queries that do your inner joins to eagerly fetch the child relationship data).

          IMO, eager loading should be used very minimally and only in those cases when you ALWAYS want to populate your relationship objects.

          I'd be curious to hear others opinions on this - as I in no way consider myself an EJB3 guru.

          • 2. Re: fetch type eager
            Alexander Hartner Expert

            You need to rethink. EAGER should be used for Composition relationships and certain exceptional cases where the contained object is always needed. Also take a look at the FETCH attribute of the EQL language.