JOOQ 不会将表中的行转换为枚举
我尝试了不同的转换方法,但它们要么没有做任何事情,要么显示错误,我尝试添加 codegen jooq,但我做不到,我找不到明确说明需要做什么的文档.
return new PageImpl<>(DSL.select(field("kk.id"),
field("kk.epk_id"),
field("kk.uir"),
field("kk.status_code", VARCHAR.asEnumDataType(StatusCode.class)), --- This is the line that is not being converted
field("kk.end_date", DATE),
field("kk.sudir_user_name"),
field("val.name_kk")).
from("ccl_test.calculation_kk kk\n" +
"join ccl_test.values_kk val\n" +
"on (case resulting_calculation_value\n" +
" when 'value_ml_model' then id_ml_model_value=val.id\n" +
" when 'value_lm' then id_lm_value=val.id\n" +
" when 'value_verifier' then id_verifier_value=val.id\n" +
" END)\n" +
"where status_code='completed'")
.orderBy(field("kk.id"))
.limit(pageable.getPageSize())
.offset(pageable.getOffset())
.fetchInto(CalculationDTOForAll.class));
这是我的枚举
public enum StatusCode {
INITIATED("initiated","Инициирован"),
ON_VERIFICATION("for_verification","На верификации"),
ON_CONFIRMATION("confirmation","На подтверждении"),
COMPLETED("completed","Завершен");
private final String value;
private final String codeName;
StatusCode(String value, String codeName) {
this.value = value;
this.codeName = codeName;
}
public String getValue() {
return value;
}
public String getCodeName() {
return codeName;
}
}
这是我的类--(这不是主实体,而是一个辅助类)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CalculationDTOForAll {
private Long id;
private Long epkId;
private String uir;
private StatusCode statusCode; --- the same Enum that is not being converted
@JsonFormat(pattern = "dd.MM.yy HH:mm:ss")
private Date endDate;
private String sudirUserName;
private String nameKk;
}
DataType.asEnumDataType()
需要参数enum
类型来实现jOOQ的org.jooq.EnumType
接口,而你的枚举不这样做。
您有三个选项可以解决此问题:
Converter
使用
DataType.asConvertedDataType()
Converter
附加到生成的代码中,我强烈建议您考虑使用,而不是仅使用 jOOQ 的基于字符串的 API。