Skip to content

Make handling of ID generation work with Oracle [DATAJDBC-350] #572

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

Closed
spring-projects-issues opened this issue Apr 1, 2019 · 3 comments
Assignees
Labels
status: duplicate A duplicate of another issue type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

Dav1dde opened DATAJDBC-350 and commented

Oracle returns oracle.sql.ROWID when no key gets generated.

 
Spring-data-jdbc calls "holder.getKey()" in org.springframework.data.jdbc.core.DefaultDataAccessStrategy#getIdFromHolder which fails with the following Exception:

Caused by: org.springframework.dao.DataRetrievalFailureException: The generated key is not of a supported numeric type. Unable to cast [oracle.sql.ROWID] to [java.lang.Number]
	at org.springframework.jdbc.support.GeneratedKeyHolder.getKey(GeneratedKeyHolder.java:79) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
	at org.springframework.data.jdbc.core.DefaultDataAccessStrategy.getIdFromHolder(DefaultDataAccessStrategy.java:323) ~[spring-data-jdbc-1.0.5.RELEASE.jar:1.0.5.RELEASE]
	at org.springframework.data.jdbc.core.DefaultDataAccessStrategy.insert(DefaultDataAccessStrategy.java:111) ~[spring-data-jdbc-1.0.5.RELEASE.jar:1.0.5.RELEASE]
	at org.springframework.data.jdbc.core.DefaultJdbcInterpreter.interpret(DefaultJdbcInterpreter.java:61) ~[spring-data-jdbc-1.0.5.RELEASE.jar:1.0.5.RELEASE]
	at org.springframework.data.relational.core.conversion.DbAction$Insert.doExecuteWith(DbAction.java:86) ~[spring-data-jdbc-1.0.5.RELEASE.jar:1.0.5.RELEASE]
	at org.springframework.data.relational.core.conversion.DbAction.executeWith(DbAction.java:55) ~[spring-data-jdbc-1.0.5.RELEASE.jar:1.0.5.RELEASE]
	... 47 common frames omitted

 

The Postgres-Fallback would also work for Oracle:

		try {
			// MySQL just returns one value with a special name
			return holder.getKey();
		} catch (InvalidDataAccessApiUsageException e) {
			// Postgres returns a value for each column
			Map<String, Object> keys = holder.getKeys();

			if (keys == null || persistentEntity.getIdProperty() == null) {
				return null;
			}

			return keys.get(persistentEntity.getIdColumn());
		}

Issue Links:

  • DATAJDBC-256 Run integration tests with Oracle
    ("depends on")

1 votes, 4 watchers

@spring-projects-issues
Copy link
Author

Dav1dde commented

There is another issue with Keygeneration and Oracle 12c (git head). Oracle requires you to explicitly set which columns it should return the generated keys from, so instead of calling org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate#update(java.lang.String, org.springframework.jdbc.core.namedparam.SqlParameterSource, org.springframework.jdbc.support.KeyHolder) we would need to call org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate#update(java.lang.String, org.springframework.jdbc.core.namedparam.SqlParameterSource, org.springframework.jdbc.support.KeyHolder, java.lang.String[]) with the ID column as "keyColumnNames" (last Argument)

@spring-projects-issues spring-projects-issues added the type: enhancement A general enhancement label Dec 31, 2020
mp911de added a commit that referenced this issue Feb 21, 2022
@mipo256
Copy link
Contributor

mipo256 commented May 23, 2023

@schauder
Copy link
Contributor

Basic Id generation worked. Id generation for non capital names will be fixed with #1666

@schauder schauder closed this as not planned Won't fix, can't repro, duplicate, stale Nov 17, 2023
@schauder schauder added the status: duplicate A duplicate of another issue label Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants