Spring batc, H2 - DataAccessResourceFailureException Could not obtain last_insert_id() Invalid parameter count for "LAST_INSERT_ID", expected count: "0"; SQL statement

Problem:

Environment:
  • Spring Batch
  • Test database: H2
org.springframework.dao.DataAccessResourceFailureException:
Could not obtain last_insert_id();

nested exception is org.h2.jdbc.JdbcSQLException:
Invalid parameter count for "LAST_INSERT_ID", expected count:
"0"; SQL statement:

update BATCH_JOB_SEQ set ID = last_insert_id(ID + 1)

<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="transactionManager" ref="transactionManager" />
        <property name="databaseType" value="mysql" />
</bean>

Solution:

<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="transactionManager" ref="transactionManager" />
        <property name="databaseType" value="h2" />
</bean>

, besides, i also had to add two sequences to my spring batch scripts:




(...)
drop sequence if exists BATCH_JOB_EXECUTION_SEQ;
drop sequence if exists BATCH_STEP_EXECUTION_SEQ;
(...)

(...)
create sequence BATCH_JOB_EXECUTION_SEQ start with 1;
create sequence BATCH_STEP_EXECUTION_SEQ start with 1;
(...)

Comments

Popular posts from this blog

Oracle - duplicate fields in RECORD,TABLE or argument list are not permitted

Oracle - ORA-29282: invalid file ID, ORA-06512: at "SYS.UTL_FILE"