How to get two different types of records from a database?

I have two tables with an FK ratio. What I want is equivalent to:

select A.*, B.* from A join B on B.A_ID = A.ID 

How do I do this efficiently in jOOQ ? In the end, I need one instance of ARecord and one of BRecord for each row.

+4
source share
1 answer

Like this

 Result<Record> result = create.select() .from(A) .join(B).on(B.A_ID.equal(A.ID)) .fetch(); 

This will result in the mapping A.*, B.* (or, more precisely, A.A1, A.A2, ..., A.AN, B.B1, ... ). Now, to convert result to ARecord and BRecord , use the Result.into(Table) method:

 ARecord a = result.into(A); BRecord b = result.into(B); 

Please note that this has known flaws. For example, if AX is a field that has a corresponding BX field (one field name), AX will contain the value BX . I registered an error report: # 1802

+1
source

Source: https://habr.com/ru/post/1432718/


All Articles