Available in versions: Dev (3.21)
This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.
User-defined type constructor expressions
Applies to ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
jOOQ's code generator supports user-defined types (UDTs) and generates meta data, records, POJOs and other artifacts for those types.
You can access the constructor expression from the generated org.jooq.UDT
type as follows. Assuming this schema using PostgreSQL syntax:
CREATE TYPE country AS ( iso_code TEXT, description TEXT ); CREATE TYPE name AS ( first_name TEXT, last_name TEXT ); CREATE TYPE address AS ( street TEXT, number TEXT, zip TEXT, city TEXT, country COUNTRY ); CREATE TABLE customer ( id INT PRIMARY KEY, first_name TEXT, last_name TEXT, street TEXT, number TEXT, zip TEXT, city TEXT, country_iso_code TEXT, country_description TEXT );
This data can be fetched with jOOQ as follows:
Record2<NameRecord, AddressRecord> result = create.select( NAME(CUSTOMER.FIRST_NAME, CUSTOMER.LAST_NAME), ADDRESS( CUSTOMER.STREET, CUSTOMER.NUMBER, CUSTOMER.ZIP, CUSTOMER.CITY, COUNTRY( CUSTOMER.COUNTRY_ISO_CODE, CUSTOMER.COUNTRY_DESCRIPTION ) )) .from(CUSTOMER) .where(CUSTOMER.ID.eq(1)) .fetchOne(); System.out.println(result.value1().getFirstName()); System.out.println(result.value1().getLastName()); System.out.println(result.value2().getCountry().getIsoCode());
Feedback
Do you have any feedback about this page? We'd love to hear it!