New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for deriving SELECT clause from mapped classes #9126
Comments
The probably preferrable solution: List<MyPojo> list4 = dsl.select(MyPojo.class).from(T).fetch(); Will require relaxing the type bound on
|
This feature corresponds to Hibernate's "projections" feature. It currently suffers from similar problems like the "projections". In the currently suggested form, there's no way to write actual expressions in the projection anymore. In jOOQ's case, the workaround is to revert to ordinary syntax. |
A subtle problem when trying to derive the projection from a POJO is that the POJO might be an immutable POJO with parameter names unavailable, so we cannot derive the order of columns from the POJO via reflection. This is almost a show stopper! |
These ideas have been tempting, but a much better solution was offered in jOOQ 3.15 via the new // Separate SQL and mapping
List<MyPojo> list1 = ctx.select(T.COL1, T.COL2).from(T).fetch(mapping(MyPojo::new));
// Embed mapping in SQL
Result<Record1<MyPojo>> list2 = ctx.select(row(T.COL1, T.COL2).mapping(MyPojo::new)).from(T).fetch(); These approaches are very powerful and composable also in case the mapping isn't trivial (nested records, nested collections), but at the same time covers the trivial cases sufficiently well. |
One annoyance that is often reported by users in different ways is that often, the projection has to be explicitly specified twice - due to Java being not a very structurally typed language, and people historically preferring to map results into POJOs.
For example, there's redundancy in these two API usages:
It would be great if there was a syntax that allowed for projecting SQL columns directly from a pre-defined mapping that is already embedded into jOOQ's DSL API, e.g.
See also discussion here: #9005 (comment)
The text was updated successfully, but these errors were encountered: