When using the “Pojo” classes created by the Jooq-Codegenerator, they (may) contain multiple constructors (default-constructor, interface-constructor, fields-constructor). For example:
public class ProductLang implements IProductLang {
...
public ProductLang() {}
public ProductLang(IProductLang value) {
this.productId = value.getProductId();
this.langId = value.getLangId();
this.name = value.getName();
this.description = value.getDescription();
}
public ProductLang(
Long productId,
Integer langId,
String name,
String description
) {
this.productId = productId;
this.langId = langId;
this.name = name;
this.description = description;
}
...
When this Pojo is now used with Records.mapping
within ad-hoc-converters (see: https://www.jooq.org/doc/latest/manual/sql-execution/fetching/ad-hoc-converter/), the Records.mapping
can not find the correct constructor, and shows an error.
Following example:
var res = Records.mapping(ProductLang::new);
Shows error:
- Cannot resolve constructor ‘ProductLang’
When the other two constructors (default-constructor, interface-constructor) are removed from the Pojo the error goes away, and the correct constructor is resolved.
The same problem is also reproducible when using the Records.mapping
within the convertFrom
function within a jooq-dsl-query.
(...).convertFrom(r -> r.map(Records.mapping(ProductLangDTO::new)))
- Can / Is
Records.mapping
intended to be used with multiple constructors?- If yes, what am i missing to make it work.