Accessing nested UDT from AbstractRecord#get(Field)

4 views
Skip to first unread message

Omar Aloraini

unread,
Feb 13, 2026, 11:01:03 AM (yesterday) 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,
6:10 AM (13 hours ago) 6:10 AM
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.
Reply all
Reply to author
Forward
0 new messages