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

Handling of spaces and underscores in AbstractBeanPropertyRowMapper [SPR-5758] #10428

Closed
spring-projects-issues opened this issue May 14, 2009 · 1 comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Pablo Krause opened SPR-5758 and commented

The class AbstractBeanPropertyRowMapper can handle underscores for matching column names to property names in a Bean, but not spaces.
I tested with a very simple patch, which consisted of chanching line 109 from:

PersistentField fieldMeta = (PersistentField) this.mappedFields.get(column);
to
PersistentField fieldMeta = (PersistentField) this.mappedFields.get(column.replaceAll(" |_", ""));

This simple change allows to match database columns either with underscores or spaces in their names with the corresponding java bean properties.
As a matter of fact, this patch makes the use of the underscoreName() method in that same class obsolete, as well as lines 202-205 in which names with and without underscores are set in the mappedFields map (I don't understand why you took this approach instead of stripping the underscores in line 109... perfomance?).

I know this is probably of use to nearly no one, but I am dealing with some legacy stored procedures which return column names with spaces so I decided to try to contribute something back.


Affects: 2.5 final, 2.5.1, 2.5.2, 2.5.3, 2.5.4, 2.5.5, 2.5.6

Referenced from: commits 8079262

@spring-projects-issues
Copy link
Collaborator Author

Thomas Risberg commented

Thanks for the suggestion. I'm stripping out any spaces in the column names. Have to keep the underscores so we can match on "birth_date" property, even if that is not a typical JavaBean naming practice, it's actually part of the existing unit tests.

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 M4 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant