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

Treat numbers as separate elements in JdbcUtils.convertPropertyNameToUnderscoreName #33828

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

brieuc-le-faucheur
Copy link

@brieuc-le-faucheur brieuc-le-faucheur commented Oct 31, 2024

Hello!

While using JdbcClient, I have encountered a specific case while querying a column containing a digit. The mapping method JdbcUtils.convertPropertyNameToUnderscoreName does not handle numbers as separate words.

Using PostgreSQL, given a table declared such as this:

create table demo (
    id text,
    name_with_1_number_in_label text
);

Querying it with a data class declared as below will result in a PSQLException:

data class DemoModel(val id: String, val nameWith1NumberInLabel: String)

@Repository
class SimpleRepository(private val jdbcClient: JdbcClient) {

    fun getBy(id: String): MutableList<DemoModel> {

        return jdbcClient.sql("""
            select * from demo where id = :id
        """.trimIndent())
            .param("id", id)
            .query(DemoModel::class.java)
            .list()
    }
}

I think isolating numbers with underscore would match naming usage more than having numbers stuck to the word preceding it in the column name.

Here is a sample project demonstrating the exception along with the PR.

numbersInJdbcColumnNames.zip

@pivotal-cla
Copy link

@brieuc-le-faucheur Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-cla
Copy link

@brieuc-le-faucheur Thank you for signing the Contributor License Agreement!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 31, 2024
@sbrannen sbrannen added the in: data Issues in data modules (jdbc, orm, oxm, tx) label Oct 31, 2024
@sbrannen sbrannen changed the title JdbcUtils.convertPropertyNameToUnderscoreName handles numbers as underscore-separated elements Treat numbers as separate elements in JdbcUtils.convertPropertyNameToUnderscoreName Oct 31, 2024
@sbrannen
Copy link
Member

Please note that the build failed for your PR.

FAILURE: Build failed with an exception.
294 actionable tasks: 139 executed, 155 from cache

* What went wrong:
Execution failed for task ':spring-jdbc:checkstyleMain'.
> A failure occurred while executing org.gradle.api.plugins.quality.internal.CheckstyleAction
   > Checkstyle rule violations were found. See the report at: file:///home/runner/work/spring-framework/spring-framework/spring-jdbc/build/reports/checkstyle/main.html
     Checkstyle files with violations: 1
     Checkstyle violations by severity: [error:2]

Please make sure you run a full local build before submitting a PR.

Thanks

@brieuc-le-faucheur brieuc-le-faucheur force-pushed the feature/jdbc-digit-support-in-camelCase-attribute-name branch from c4b7aea to 81ab792 Compare October 31, 2024 13:29
@brieuc-le-faucheur
Copy link
Author

Hello @sbrannen ! I updated the PR so that the full build passes. Sorry for the inconvenience.

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) status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants