1 Reply Latest reply on May 7, 2003 6:14 AM by Juha Lindfors

    Finders & Loading of Relationships

    Peter Spiess Newbie

      I thought I understood how to optimize the loading of relationships, but JBoss 3.2.0 is not doing what I expect.

      I have three tables that I am currently working with. I am doing an a finder method against one bean that navigates to the two related beans (for search criteria as well as ordering - I'm using JBossQL). Then, I have an eager load group set up that will load the two relationship fields and my strategy is "on-find". Next, on each relationship, I have read-ahead strategies of on-find that use eager-load-groups on each of the two related beans. These load groups grab only the once necessary field from each related bean.

      It looks like all of that configuration works since I can see the SQL that JBoss is executing and it grabs all of the necessary data from all three tables. However, when I iterate through this returned collection of beans (all within the same transaction), JBoss loads the related fields by issuing a separate query to each related bean. Since my list is about 500 items long, JBoss ends up doing about 1001 queries, when it looks like it could have gotten away with one.

      Am I doing something wrong? Should it be able to load three beans using one finder method?

      I can post the jbosscmp-jdbc.xml entries if that would be useful, I thought I would attempt to explain first.

      Thanks!

      Peter