Repository navigation
Closed
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)status: backportedAn issue that has been backported to maintenance branchestype: regressionA bug that is also a regression
Milestone
Description
John Ahlroos opened SPR-16495 and commented
When running the following code:
// Inserts a row and returns the generated id
public String performInsert()
{
SimpleJdbcInsert insert = new SimpleJdbcInsert(dataSource)
.withTableName(LOG_TABLE_NAME)
.withSchemaName(SCHEMA_NAME)
.usingGeneratedKeyColumns(ID_COLUMN)
.usingColumns(VALUE_COLUMN);
KeyHolder keyHolder = insert.executeAndReturnKeyHolder(Collections.singletonMap(VALUE_COLUMN, json));
String id = (String) keyHolder.getKeys().get(ID_COLUMN);
return id;
}This code will work with Spring JDBC 4.3.6.RELEASE but if I change it to 4.3.7.RELEASE or above it will fail in:
Caused by: java.lang.NullPointerException
at org.springframework.jdbc.core.metadata.OracleTableMetaDataProvider.lookupDefaultSchema(OracleTableMetaDataProvider.java:79)
at org.springframework.jdbc.core.metadata.OracleTableMetaDataProvider.<init>(OracleTableMetaDataProvider.java:68)
at org.springframework.jdbc.core.metadata.TableMetaDataProviderFactory$1.processMetaData(TableMetaDataProviderFactory.java:74)
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:336)
at org.springframework.jdbc.core.metadata.TableMetaDataProviderFactory.createMetaDataProvider(TableMetaDataProviderFactory.java:64)
at org.springframework.jdbc.core.metadata.TableMetaDataContext.processMetaData(TableMetaDataContext.java:206)
at org.springframework.jdbc.core.simple.AbstractJdbcInsert.compileInternal(AbstractJdbcInsert.java:280)
at org.springframework.jdbc.core.simple.AbstractJdbcInsert.compile(AbstractJdbcInsert.java:266)
at org.springframework.jdbc.core.simple.AbstractJdbcInsert.checkCompiled(AbstractJdbcInsert.java:313)
at org.springframework.jdbc.core.simple.AbstractJdbcInsert.doExecuteAndReturnKeyHolder(AbstractJdbcInsert.java:396)
at org.springframework.jdbc.core.simple.SimpleJdbcInsert.executeAndReturnKeyHolder(SimpleJdbcInsert.java:142)
Affects: 4.3.14
Issue Links:
- SimpleJdbcCall can't access synonyms in Oracle database [SPR-16478] #21022 SimpleJdbcCall can't access synonyms in Oracle database
- Drop NativeJdbcExtractor mechanism in favor of java.sql.Connection.unwrap() [SPR-14670] #19234 Drop NativeJdbcExtractor mechanism in favor of java.sql.Connection.unwrap()
Referenced from: commits f2dc075, 766e602
Backported to: 4.3.15
Metadata
Metadata
Assignees
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)status: backportedAn issue that has been backported to maintenance branchestype: regressionA bug that is also a regression
Activity
spring-projects-issues commentedon Feb 14, 2018
Juergen Hoeller commented
This turns out to be rather odd: The only reference that can be
nulladd that point is theConnectionreturned fromDatabaseMetaData.getConnection()... and I can't see any change in 4.3.7 that would have caused a regression here either. So we can be defensive againstnullthere... but why is the metadataConnectionnot available in the first place?spring-projects-issues commentedon Feb 14, 2018
Juergen Hoeller commented
This seems to be a side effect of the #19234 refactoring: Instead of catching
Exceptionas we did before, we changed it toSQLException... not covering an NPE anymore. Of course we never meant to cover an NPE in the first place, so by defensively checking whether theConnectionisnullthere, we should be equally safe.spring-projects-issues commentedon Feb 14, 2018
John Ahlroos commented
Here is the difference in the implementations of lookupDefaultSchema().
In 4.3.6 we consume the NPE in an empty catch clause:
While in 4.3.7 we only catch the SQLExceptions and let the NPE pass:
That is most likely why it stopped working.
Why the connection is null from
DatabaseMetaDataI don't know, it seems to be the case for both versions. The implementation (SerialDatabaseMetaData) I get there is coming from Weblogic's client library (wlfullclient.jar) so it might be a bug there. Anyway, I think it might be a good idea to revert the Exception handling back as this method is only a lookup method that tries the guess the schema.spring-projects-issues commentedon Feb 14, 2018
Juergen Hoeller commented
We posted at almost the same time there, coming to the same conclusion :-)
Since we're generally trying to avoid accidental over-catching, I've added a not-null check for the
Connectioninstead, logging a specific debug message in that case. A similar check applies to theinitializeWithTableColumnMetaDataimplementation now when trying to include synonyms.