I use Spring Data JDBC with an Oracle database and I set a custom id on my entity with a BeforeSaveEvent
processor.
@Bean
public DataFieldMaxValueIncrementer incrementer() {
OracleSequenceMaxValueIncrementer incrementer = new OracleSequenceMaxValueIncrementer();
incrementer.setDataSource(metahubDatasource());
incrementer.setIncrementerName("TL_SEQ");
return incrementer;
}
@Bean
public ApplicationListener<?> idSetting() {
return (ApplicationListener<BeforeSaveEvent>) event -> {
if (event.getEntity() instanceof TL) {
setIds((TL) event.getEntity());
}
};
}
private void setIds(TL tl) {
tl.setId(incrementer().nextLongValue());
}
When I try to persist this entity the exception below is thrown.
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)
at org.springframework.data.jdbc.core.DefaultDataAccessStrategy.getIdFromHolder(DefaultDataAccessStrategy.java:323)
at org.springframework.data.jdbc.core.DefaultDataAccessStrategy.insert(DefaultDataAccessStrategy.java:111)
at org.springframework.data.jdbc.core.DefaultJdbcInterpreter.interpret(DefaultJdbcInterpreter.java:73)
at org.springframework.data.relational.core.conversion.DbAction$InsertRoot.doExecuteWith(DbAction.java:110)
at org.springframework.data.relational.core.conversion.DbAction.executeWith(DbAction.java:55)
...
How can I configure the generated key column to avoid this exception or how can I configure that no generated key is expected?