POJO Mapping in JOOQ regardless of parameter order

心不动则不痛 提交于 2020-04-13 10:45:09

问题


When I generate the JOOQ POJOs, the constructor follows the same order for the parameters as the fields in the database table.

When querying the table and using fetchInto this works fine, as long as the order of the POJO constructor parameters and the order of the fields in the database table are the same.

return create
      .select()
      .from(KEY)
      .fetchInto(Key.class);

How can I map the query above into Key.class regardless of the constructor parameter order? E.g. can I use something like mapstruct in conjunction with JOOQ?


回答1:


You can annotate your constructor with @java.beans.ConstructorProperties. We also support Java 8's parameter name reflection (see https://github.com/jOOQ/jOOQ/issues/4627), but that does not seem as reliable, as it depends on flags you set when compiling your own code.

See also the documentation of DefaultRecordMapper.



来源:https://stackoverflow.com/questions/60926102/pojo-mapping-in-jooq-regardless-of-parameter-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!