Hi Daryl, Are you sure your native query is what you want? There might be some caveats with join precedence. No idea which database you run against but to take an example, MySQL has the following:
http://pento.net/2009/04/03/join-and-comma-precedence/ Cheers, Milosz > On Thu, Apr 9, 2009 at 9:20 PM, Daryl Stultz wrote: > > > > > I gave this a good testing and have some interesting (to me) results. My > > real object model isn't quite like this, it's a little more complicated. > > > Things seem to be running bad this morning tho' I haven't changed anything > fundamentally from last night. The core of my real model looks like this: > > Module > KeyGroup > Key > LocalizedString > > At present I have in the database 1 module, 11 key groups, 99 keys and 99 > localized strings (one localized strings per key, keys spread over key > groups). > All relationships are LAZY. > > This is my main line: > > OpenJPAEntityManager em = OpenJPAPersistence.cast(entityManager); > > FetchPlan plan = em.getFetchPlan(); > plan.addField(Module.class, "keyGroups"); > plan.addField(KeyGroup.class, "keys"); > plan.addField(Key.class, "localizedStrings"); > > Module module = Module.findById(2); // gets em, runs query > containing "join fetch m.keyGroups" > module.printGraph(System.out); > > If I comment out everything but the last 2 lines, I get the full set of data > with queries interleaved in my output as expected. Running the above gets me > the module, all key groups and all keys but only localized strings for one > key group. Interestingly this key group is the last to be retrieved in my > native test query with no ordering: > > select Modules.name, KeyGroups.name, Keys.name, LocalizedStrings.value > from Modules > left join KeyGroups on KeyGroups.moduleId = Modules.moduleId > left join Keys on Keys.keyGroupId = KeyGroups.keyGroupId > left join LocalizedStrings on LocalizedStrings.keyId = Keys.keyId > > Any idea what I could be doing wrong? > > -- > Daryl Stultz > _____________________________________ > 6 Degrees Software and Consulting, Inc. > http://www.6degrees.com > mailto:[email protected] >
