Skip to content
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

Introduce RowMapper with automatic binding to fields #26594

Closed
membersound opened this issue Feb 23, 2021 · 6 comments
Closed

Introduce RowMapper with automatic binding to fields #26594

membersound opened this issue Feb 23, 2021 · 6 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@membersound
Copy link

membersound commented Feb 23, 2021

BeanPropertyRowMapper requires setters being present. Which is fine if you have some.

But if you only have a simple dto class for some reason, and want to make use of the mapper, it requires to create setters just for that.

It would be nice if we could have some DirectFieldRowMapper additionally, similar to:
https://gist.github.com/stianl/6629122#file-directfieldrowmapper

Spring already allows direct field mapping for mvc with DataBinder.initDirectFieldAccess().
So why not providing a direct mapper also for jdbc beans, that can simply operate on public fields?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 23, 2021
@sbrannen
Copy link
Member

Are you familiar with org.springframework.jdbc.core.DataClassRowMapper introduced in Spring Framework 5.3?

Does the "data class constructor with named parameters corresponding to column names" support meet your needs?

@sbrannen sbrannen added in: data Issues in data modules (jdbc, orm, oxm, tx) status: waiting-for-feedback We need additional information before we can continue type: enhancement A general enhancement labels Feb 23, 2021
@membersound
Copy link
Author

membersound commented Feb 23, 2021

No, as far as I understood the DataClassRowMapper only adds the ability to let the mapper create the object using a constructor. If you have a dto with public fields, you usually won't have a constructor matching all the fields.

Like, if the db row has 20 columns, you would have to introduce a 20 column constructor to make it work. This is no advantage over creating 20 setters.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 23, 2021
@sbrannen sbrannen removed the status: feedback-provided Feedback has been provided label Feb 23, 2021
@sbrannen
Copy link
Member

Like, if the db row has 20 columns, you would have to introduce a 20 column constructor to make it work. This is no advantage over creating 20 setters.

Sure. There's no real benefit in that.

@sbrannen sbrannen changed the title Enhance BeanPropertyRowMapper with DirectField support Introduce RowMapper with automatic binding to fields Feb 23, 2021
@sbrannen sbrannen removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 23, 2021
@sbrannen sbrannen added this to the 5.x Backlog milestone Feb 23, 2021
@sbrannen
Copy link
Member

We've assigned this proposal to the 5.x Backlog for potential inclusion in 5.3.x

@membersound
Copy link
Author

Would still be great if that feature could get some investigation.

@jhoeller jhoeller self-assigned this Aug 14, 2023
@jhoeller jhoeller modified the milestones: 6.x Backlog, 6.1.0-M4 Aug 14, 2023
@jhoeller
Copy link
Contributor

I'm introducing a new SimplePropertyRowMapper with flexible constructor/property/field mapping in 6.1 now, used by the query(Class) method on JdbcClient (see #30931). Along the lines of our recent SimplePropertySqlParameterSource which is used for the paramSource(Object) method on JdbcClient, this provides a similarly designed fallback model for populating the target object which effectively supersedes DataClassRowMapper when no specific customization is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants