私のアプリケーションはシーケンスを使用しており、同様のセットアップを持つ HSQLDB インメモリ データベースを使用して junit テスト環境をセットアップしようとしています。これは、シーケンスとその作成を構成した方法です。
<?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>
そして create-ddl.sql の内容:
CREATE SEQUENCE public.agent_logs_seq;
結果は
java.sql.SQLException: Sequence already exists in statement
しかし、それをコメントアウトすると、
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]
私がシーケンスを使用しようとしている方法:
DataFieldMaxValueIncrementer incrementer =
(DataFieldMaxValueIncrementer) context.getBean("logSeqIncrementer");
Integer logId = Integer.valueOf(incrementer.nextIntValue());
編集:正しいシーケンスクラスが使用されるように上記の詳細を変更しました。ただし、問題は解決しませんでした。