Let's say I want to select the max value of a specific field:
getContext().select( ..., //several fields
DSL.max(MY_TABLE.SCORE).as("max_score"))
.from(MY_TABLE)
.where(...)
.groupBy(...);
I fetch the results, and now I want to get the values of a specific record, so I do:
Integer maxScore = (Integer) record.get("max_score");
This is working just fine, but I have 2 issues with this approach:
- Type safety is lost - I must cast the value to
Integer. - Although this field will never be null, Jooq is not aware of this. If I define maxScore as
intinstead ofInteger, I get a warning on this line:Unboxing of 'record.get("max_score")' may produce 'NullPointerException'. For table's "not-null" fields, I don't get this warning.
Is there a way to overcome these issues?