On Wednesday, July 2, 2014 11:42:40 PM UTC-7, Lukas Eder wrote:
>
>
> 2014-07-01 16:57 GMT+02:00 Garret Wilson <[email protected] 
> <javascript:>>:
>
>> Hi, Lukas. I'm not sure you understood what I meant by "duplicate 
>> information", 
>>
>
> I'm pretty sure I did: You're repeating "parent" (e.g. author) record data 
> for each "child" (e.g. book)
>  
>
>> and what I meant by "multiple queries... less efficient".
>>
>
> Hmm, what could you mean other than N+1 querying? :)
>


Ah, pardon me, so you did understand. :) I had assumed that there must be a 
nice and tidy jOOQ solution, and simply I must not have been explaining 
myself clearly. I see now that this is a larger, common issue---this is why 
people use Hibernate, monster that it is.
 

> ... You have these options from my point of view:
>
> 1. Use joins and implement that grouping yourself, but factor out common 
> parts. Right now, you have a lot of redundant logic because you're 
> explicitly tying stuff to the AUTHOR / BOOK relation. I'm sure there are 
> elements that can be factored out generically. jOOQ provides you with 
> foreign key meta information
>

Yeah, I can definitely refactor some of the stuff above. I was just looking 
for some help from jOOQ.
 

> 2. Use joins and use jOOQ's existing Result.intoGroups() methods. It'll 
> help doing the "grouping" (which you currently do manually, and iteratively)
>

That's interesting, but from a cursory examination (pardon the 
unintentional pun) it doesn't seem to support cursors, meaning I'm going to 
get a humongous map of all those records, each of them with duplicate, 
duplicate, duplicate information for each of the items in the parent 
relationship.
 

> 3. Use several queries instead of joins, but don't fetch each author for 
> each book. Fetch all books first, and then fetch *ALL* authors for *ALL* 
> books
>

Yes, that would be cleaner, but I would guess that's not as efficient as a 
join. (I am *not* an SQL query expert.) 

The "N+1 problem" seems to be two separate issues:


   1. *How to nicely map stuff from joins into objects.* This is where 
   Hibernate is light years ahead, I guess. But I would have thought that jOOQ 
   would give me some utilities to help with this. You did give some links to 
   some mappers, which I will look into, but I didn't see any examples offhand.
   2. *How to efficiently query data for a hierarchy of objects.* From 
   reading a tiny bit, this seems like a general problem of relational 
   databases, one that Hibernate may not have solved, either.


Thanks for all the links. I'll do some more research and see where that 
gets me.

Garret

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to