Accessing nested UDT from AbstractRecord#get(Field)

6 views
Skip to first unread message

Omar Aloraini

unread,
Feb 13, 2026, 11:01:03 AM (4 days ago) Feb 13
to jOOQ User Group
Not sure if this is suppose to work or not.

Assume I have a table A with a UDT field b of type B and that B has a field C of type String. The following doesn't work: 

ARecord rec = ...;
rec.get(A.B.C) => exception: field not contained in row type..

I found this https://github.com/jOOQ/jOOQ/issues/16721 but not sure if it's the same.

I debugged my code and the full path of the field as available at runtime "a"."b"."c". I going to experiment with getQualifiedName and breakdown the name and do the nested access manually.

Omar Aloraini

unread,
Feb 14, 2026, 6:10:23 AM (4 days ago) Feb 14
to jooq...@googlegroups.com
I have managed to get it to work, only tested it for one level of nesting:

@SuppressWarnings("unchecked")
public static <T> T get(Record record, Field<?> field) {
if (field instanceof TableField<?,?>) return (T) field.get(record);

Name[] parts = field.getQualifiedName().parts();
Record current = record;
for (int i = 1; i < parts.length; i++) {
Name part = parts[i];
Field<?> currentField = current.field(part);
if (currentField instanceof UDTPathField<?,?,?> udtPath) {
current = current.get(udtPath, UDTRecord.class);
} else {
return (T) current.get(currentField);
}
}

throw new IllegalStateException();
}

I'm using a converter with my UDTs(through forcedTypes) so a normal Record::get would return the user type, which is not a record. To workaround this I force the conversion using Record::get(Field, Class), for this to work you need to add the following to your ConverterProvider:

if (UDTRecord.class.isAssignableFrom(uType)) {
for (Converter<?, ?> converter : converters) {
if (converter.toType().equals(tType) && UDTRecord.class.isAssignableFrom(converter.fromType())) {
return converter.inverse();
}
}
}
where 'converters' is a list of your UDT converter.


--
You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/H1WB-i8q-cI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jooq-user/e65ab2db-b895-48e9-8e1c-c7363ae12a5an%40googlegroups.com.

Lukas Eder

unread,
7:42 AM (11 hours ago) 7:42 AM
to jooq...@googlegroups.com
Hello,

Thanks for your message. #16721 is a different issue. This is the one you were looking for:

I'll check if this can be implemented for jOOQ 3.21

While path access is certainly useful on its own, do note that you can also write rec.getA().getB().getC(), or rec.a.b.c in Kotlin.

Best Regards,
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.
To view this discussion visit https://groups.google.com/d/msgid/jooq-user/CAJ0wWSiNSA9HG%3DmcvC_fD9h%3DNXMRx%3DEAKnk-to2MZYB5pU781w%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages