You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Presently DataClassRowMapper appears to assume that all database columns use snake_case
Say I have a kotlin class like:
data class MyClass(val myFoo: String, val myBar: String)
and a database table with columns myFoo, myBar
a naive selection like
select myFoo, myBar
FROM ...
will fail, because the mapper will expect the columns to be named with underscores.
This can be worked around by adding aliases with underscores:
select myFoo as my_foo, myBar as my_bar
FROM ...
But this is less than ideal. Ideally this would be configurable and support a few standard formats out of the box, e.g. snake_case, camelCase, PascalCase.
The text was updated successfully, but these errors were encountered:
Presently DataClassRowMapper appears to assume that all database columns use snake_case
This is by design.
DataClassRowMapper extends BeanPropertyRowMapper, and the class-level Javadoc for BeanPropertyRowMapper states:
Column values are mapped based on matching the column name as obtained from result set meta-data to public setters for the corresponding properties. The names are matched either directly or by transforming a name separating the parts with underscores to the same name using "camel" case.
...
To facilitate mapping between columns and fields that don't have matching names, try using column aliases in the SQL statement like select fname as first_name from customer.
...
Please note that this class is designed to provide convenience rather than high performance. For best performance, consider using a custom RowMapper implementation.
There is indeed a design convention for either the lower-cased name matching directly or the underscored name matching. However, this seems to be inconsistently implemented for constructor argument resolution in DataClassRowMapper where only the underscored naming is actually applied. I'll align this for 5.3.18.
jhoeller
changed the title
Support column formats other than underscored in DataClassRowMapper
BeanPropertyRowMapper's support for direct column name matches is missing in DataClassRowMapper
Mar 29, 2022
Thanks @jhoeller - you mention "lower-cased" name matching directly, which is slightly different than what the documentation says The names are matched either directly or by...
if i have a class property and database column with exactly matching, but non-lowercase, names e.g. in my example above, would that still not be supported?
Presently DataClassRowMapper appears to assume that all database columns use
snake_case
Say I have a kotlin class like:
and a database table with columns
myFoo, myBar
a naive selection like
will fail, because the mapper will expect the columns to be named with underscores.
This can be worked around by adding aliases with underscores:
But this is less than ideal. Ideally this would be configurable and support a few standard formats out of the box, e.g.
snake_case
,camelCase
,PascalCase
.The text was updated successfully, but these errors were encountered: