Custom types in DSL.newRecord

213 views
Skip to first unread message

col...@plevium.ca

unread,
Jan 25, 2016, 10:47:12 AM1/25/16
to jOOQ User Group
What is the recommended way to handle a use case like this:
A Client object which has 2 fields of type Address: homeAddress, workAddress
A clients table which has expanded columns for this. e.g. home_address_street_number, home_address_city, etc...  (so like 5 columns for each address)

Currently DSL.newRecord doesn't pick it up at all, I am assuming because the column name can't find a match because of the custom Address type. How to best solve this? I was looking at RecordProviderMapper but I'm not sure if this will work for a case where you have 5 columns mapping to one object (which contains 5 fields). Also the fact that there are multiple of that type (home and work).

Thoughts?

Lukas Eder

unread,
Jan 25, 2016, 10:56:54 AM1/25/16
to jooq...@googlegroups.com
Hi Collin,

There's a (currently undocumented) feature that supports to-one mappings in the DefaultRecordMapper, if your columns are labelled "home.street.number" or "home.city". This works for target types like:

class Client {
    Address home;
    Address work;
}

class Address {
    Street street;
    String city;
}

class Street {
    String number;
}

It is currently undocumented, because this is still a moving target, and we haven't covered all the edge cases that might appear. Your feedback as a beta-tester of this functionality is thus very welcome :-) (it would be great if we could improve this functionality!)

Note that this currently only works when mapping from Record -> POJO, not when "unmapping" from POJO -> Record.

I hope this helps
Lukas

--
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 jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Collin

unread,
Jan 25, 2016, 11:03:07 AM1/25/16
to jOOQ User Group
Hmm... I am needing this for insert so I guess this approach wouldn't work then?

The code is simply:
R record = (R) dsl.newRecord(CLIENTS, entity);

Lukas Eder

unread,
Jan 25, 2016, 11:15:34 AM1/25/16
to jooq...@googlegroups.com
Yes, this is what I meant by "unmapping". You have a nested entity (i.e. POJOs nested in other POJOs, if you will), and you want to flatten this data structure into a jOOQ record.

This is currently not possible with out-of-the-box functionality. The RecordUnmapper API is a pending feature request, which we have not yet implemented:

So, as of now, you will have to implement a solution entirely outside of jOOQ, I'm afraid.

Best Regards,
Lukas

Lukas Eder

unread,
Apr 26, 2017, 6:07:18 AM4/26/17
to jOOQ User Group
For the record, the RecordUnmapper and RecordUnmapperProvider SPIs are implemented in jOOQ 3.10, containing the current default behaviour of unnesting flat POJOs, arrays, maps.

If time permits, we'll also implement unmapping nested POJOs (https://github.com/jOOQ/jOOQ/issues/6159), arrays and maps (https://github.com/jOOQ/jOOQ/issues/6160) in 3.10. If not, in a later release.

Thanks,
Lukas
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages