My application uses sequences, and I'm trying to set up junit test environment with HSQLDB in-mem database that would have a similar setup. This is how I've configured the sequences and their creation:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" lazy-init="true"
destroy-method="close">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:mem:test"/>
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
<bean id="logSeqIncrementer" class="org.springframework.jdbc.support.incrementer.HsqlSequenceMaxValueIncrementer">
<property name="dataSource" ref="dataSource" />
<property name="incrementerName" value="public.agent_logs_seq" />
</bean>
<bean id="offerSeqIncrementer" class="org.springframework.jdbc.support.incrementer.HsqlSequenceMaxValueIncrementer">
<property name="dataSource" ref="dataSource" />
<property name="incrementerName" value="public.offers_seq" />
</bean>
<jdbc:embedded-database
id="test"
type="HSQL">
<jdbc:script
location="classpath:/create-ddl.sql" />
</jdbc:embedded-database>
</beans>
And contents of create-ddl.sql:
CREATE SEQUENCE public.agent_logs_seq;
Results in
java.sql.SQLException: Sequence already exists in statement
but if I comment that out, I get
java.lang.AssertionError: Unexpected exception:
org.springframework.dao.DataAccessResourceFailureException:
Could not obtain sequence value; nested exception is
java.sql.SQLException: Sequence not found:
AGENT_LOGS_SEQ in statement [call next value for public.agent_logs_seq]
The way I'm trying to use the sequence:
DataFieldMaxValueIncrementer incrementer =
(DataFieldMaxValueIncrementer) context.getBean("logSeqIncrementer");
Integer logId = Integer.valueOf(incrementer.nextIntValue());
Edit: changed the details above so that correct sequence class would be used. It didn't solve the issue, however.