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

The BeanPropertyRowMapper does not work for field names ending with "numbers" which worked for 3.1 [SPR-16937] #21476

Closed
spring-projects-issues opened this issue Jun 12, 2018 · 2 comments
Assignees
Labels
in: core status: declined

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jun 12, 2018

Yash Bajaj opened SPR-16937 and commented

Class name : BeanPropertyRowMapper

Package : package org.springframework.jdbc.core

Issue : The field name that has an "underscore" in it, lets say person_name_1 is a column name in a database which is also present in the result set. Using BeanPropertyRowMapper, you could map the result set to a model class in your codebase. If you are in a JAVA environment, you probably would choose to use personName1 as the choice of the field name. In the Spring-JDBC 3.1 version, the mapper would map them correctly. But, in the Spring-JDBC 4.3 version, the mapper is not able to map it.

Official documentation - https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/core/BeanPropertyRowMapper.html

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.

Root cause : If you look into the class from the latest version, the initialize method calls the underScoreName() method here - https://github.com/spring-projects/spring-framework/blob/master/spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java#L245 

This method's logic maps personName1 to person_name1.

Whereas if you look into the class  from the 3.1 version, the initialize method calls the the underScoreName() method here - https://github.com/spring-projects/spring-framework/blob/3.1.x/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java#L165

This method's logic maps personName1 to person_name_1.

This is not a backward compatible logic change. The existing systems would break whose column names end with a number.

Could you please look into it or let me know if there's something that I'm missing or this isn't a valid usecase at all?

 

 

 


Affects: 4.3.17, 5.0.6

Issue Links:

  • #15177 BeanPropertyRowMapper underscoreName
  • #17807 BeanPropertyRowMapper should always call toLowerCase with US encoding
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jun 12, 2018

Juergen Hoeller commented

I'm afraid this was an intentional change back in 3.2 (#15177), following the original intentions of that algorithm.

If you'd like to restore the previous behavior or some other naming policy, please consider overriding BeanPropertyRowMapper.underscoreName(String) accordingly.

@msangel
Copy link

@msangel msangel commented May 26, 2022

Why simply not allow an alternative name via @Comumn annotation if it present?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core status: declined
Projects
None yet
Development

No branches or pull requests

3 participants