2013/7/28 <[email protected]> > What options do I have if the 2 tables I am joining have the same column > name? Most of my tables have audit info like "created_date", "modified_by".
There's no automatic solution to this, I'm afraid. While most SQL dialects allow for two columns to use the same name in outermost SELECT clauses (not in nested SELECTs), it's usually not possible to distinguish them by name. Cheers Lukas On Thursday, January 10, 2013 2:47:20 AM UTC-5, Lukas Eder wrote: > >> Hi Peter, >> >> Yes, for your specific case, you're lucky. You can use Record.into(Table): >> http://www.jooq.org/javadoc/**latest/org/jooq/Record.html#** >> into(org.jooq.Table)<http://www.jooq.org/javadoc/latest/org/jooq/Record.html#into(org.jooq.Table)> >> >> It maps an arbitrary record onto another record type, given a table. In >> other words, the two statements are similar: >> >> // Using into() >> SiteRecord site = joinedRecord.into(SITE); >> >> // Manually moving values: >> SiteRecord site = sql.newRecord(SITE); >> // [ copy all relevant values from joinedRecord to site ] >> // [ transferring "changed" state from joinedRecord to site ] >> >> If you can guarantee primary key integrity, you can also modify and store >> / delete the SiteRecords, etc. >> >> Beware that joining may produce ambiguities, if several tables contain >> the same column names. >> Beware that renaming columns may keep Record.into(Table) from working >> properly >> >> Cheers >> Lukas >> >> >> 2013/1/9 Peter Ertl <[email protected]> >> >> we all know mapping a single table into a pojo-style record works: >>> >>> Result<SiteRecord> records = sql.selectFrom(SITE).fetch(); >>> >>> also we know this works when joining tables: >>> >>> Result<Record> joinedRecords = sql.select().from(SITE).** >>> leftOuterJoin(ACCOUNT).onKey()**.fetch(); >>> >>> Since there is already logic for mapping fields into type-safe records, >>> would this orm-style of mapping be possible? >>> >>> for (Record joinedRecord : joinedRecords) { >>> SiteRecord site = joinedRecord.getRecord(**SiteRecord.class); >>> AccountRecord account = joinedRecord.getRecord(**AccountRecord.class); >>> // bla >>> } >>> >>> Regards, >>> Peter >>> >> >> -- > 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/groups/opt_out. > > > -- 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/groups/opt_out.
