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

When using Oracle, JdbcClient.update(KeyHolder) does not work without explicit key column names #31607

Closed
zakaria-shahen opened this issue Nov 14, 2023 · 1 comment
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@zakaria-shahen
Copy link
Contributor

zakaria-shahen commented Nov 14, 2023

Hello
When use Oracle DB The JdbcClient.update(KeyHolder) method not work with named parameters

Example:

        jdbcClient.sql(insert_sql)
                .paramSource(objectModel)
                .update(keyHolder);
        var id = keyHolder.getKey();

and throw

org.springframework.dao.DataRetrievalFailureException: The generated key type is not supported. Unable to cast [oracle.sql.ROWID] to [java.lang.Number].
	at org.springframework.jdbc.support.GeneratedKeyHolder.getKeyAs(GeneratedKeyHolder.java:86) ~[spring-jdbc-6.1.0-RC2.jar:6.1.0-RC2]
	at org.springframework.jdbc.support.GeneratedKeyHolder.getKey(GeneratedKeyHolder.java:65) ~[spring-jdbc-6.1.0-RC2.jar:6.1.0-RC2]

and when use NamedParameterJdbcOperations as workaround, it works

        namedParameterJdbcOperations.update(
                insert_sql, new SimplePropertySqlParameterSource(objectModel), keyHolder, new String[] {"id"}
        );
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 14, 2023
@jhoeller jhoeller added in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 15, 2023
@jhoeller jhoeller self-assigned this Nov 15, 2023
@jhoeller jhoeller added this to the 6.1.0 milestone Nov 15, 2023
@jhoeller jhoeller changed the title When use Oracle DB The JdbcClient.update(KeyHolder) method not work with named parameters When using Oracle, JdbcClient.update(KeyHolder) does not work without explicit key column names Nov 15, 2023
@jhoeller
Copy link
Contributor

I ended up introducing an update(KeyHolder generatedKeyHolder, String... keyColumnNames) variant which supports both indexed and named parameters (even if it is more likely to be used with named parameters).

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

3 participants