On Tue, Jul 26, 2011 at 6:02 AM, M. Walter <marc.wal...@sbb.ch> wrote:
> I did the following: > > final OpenJPAQuery ojpaQuery = > OpenJPAPersistence.cast(em.createNamedQuery( > StammdatenQueryNames.FIND_ALL_BP.name())); > ojpaQuery.getFetchPlan().removeFetchGroup(FetchGroup.NAME_DEFAULT); > ojpaQuery.getFetchPlan().addFetchGroup("short"); > final List<Bp> result = ojpaQuery.getResultList(); > > All fields and all relationships are loaded. Another idea? > > I've been following this thread and was inspired to try this myself to improve a performance problem. I seem to be getting a similar outcome (no effect). My query code looks like this: System.out.println("**** 1"); final OpenJPAQuery ojpaQuery = OpenJPAPersistence.cast(query); ojpaQuery.getFetchPlan().removeFetchGroup(FetchGroup.NAME_DEFAULT); // no apparent effect ojpaQuery.getFetchPlan().clearFetchGroups(); // try both ways ojpaQuery.getFetchPlan().addFetchGroup("ScheduledAssignment.annotated"); salist.addAll(query.getResultList()); System.out.println("**** 2"); I'm getting a boatload of queries between the **** 1 and ****2. I'm specifically trying to combat an N+1 problem, not sure this approach will work. Anyway, my annotations on the root entity look like this: @FetchGroups({ @FetchGroup(name = "ScheduledAssignment.annotated", attributes = { @FetchAttribute(name = "request"), @FetchAttribute(name = "parentScheduledAssignment", recursionDepth = 0), @FetchAttribute(name = "user"), @FetchAttribute(name = "standInUser"), @FetchAttribute(name = "role"), @FetchAttribute(name = "manualEntry"), @FetchAttribute(name = "brokenRuleLookup") }) }) The SQL trace looks like this, I'm showing only the select for only the root table: SELECT t0.scheduledassignmentid, t0.addedby, t0.caseid, t0.scatterautomationid, t0.modifiedby, t0.rotationassignmentid, t0.brokencustomruleexplanation, t0.addedon, t0.manualentry, t0.modifiedon, t0.timedebit The first line is the PK, the second line FKs, the third basic. There are more FKs and more basic props. I can't see any pattern to this. After some back and forth, the select never changes (from t0, I didn't analyze the others). In fact I reverted to my code prior to using the FetchGroup and it's no different. I've made all my FKs lazy to no effect. I can't even say that it appears the default fetch group is still active. What's being selected doesn't even seem to match that. I'm using OpenJPA 1.2.2 -- Daryl Stultz _____________________________________ 6 Degrees Software and Consulting, Inc. http://www.6degrees.com http://www.opentempo.com mailto:daryl.stu...@opentempo.com