我使用 hsqldb 进行单元测试。我的生产使用 Oracle 11G Db。当我如上所述运行我的启动脚本时:
<jdbc:embedded-database id="dataSource" type="HSQL">
</jdbc:embedded-database>
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
<jdbc:script location="classpath:/sql/init-cct-schema.sql" separator=";" />
<jdbc:script location="classpath:/sql/init-cct-insert.sql" separator=";" />
</jdbc:initialize-database>
我真的是HSQL 文档中的触发器示例。
我看到了这篇文章:但是他的解决方案对我不起作用,或者我不明白。
我一直有这个错误:
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at
...
... 38 more
Caused by: org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement at line 9 of resource class path resource [sql/init-cct-schema.sql]: CREATE TRIGGER TI_TYPE_MVT BEFORE INSERT ON TYPE_MVT REFERENCING NEW AS newrow FOR EACH ROW BEGIN ATOMIC IF newrow.TYPE_MVT_PK is null THEN SET newrow.TYPE_MVT_PK = SQ_TYPE_MVT.nextval
at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.executeSqlScript(ResourceDatabasePopulator.java:199)
at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.populate(ResourceDatabasePopulator.java:132)
at org.springframework.jdbc.datasource.init.CompositeDatabasePopulator.populate(CompositeDatabasePopulator.java:55)
at org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:45)
... 41 more
Caused by: java.sql.SQLSyntaxErrorException: unexpected end of statement: required: ;
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.execute(Unknown Source)
at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.executeSqlScript(ResourceDatabasePopulator.java:184)
... 44 more
Caused by: org.hsqldb.HsqlException: unexpected end of statement: required: ;
at org.hsqldb.error.Error.parseError(Unknown Source)
这是我的触发器:
SET DATABASE SQL SYNTAX ORA TRUE;
CREATE TRIGGER TI_TYPE_MVT BEFORE INSERT ON TYPE_MVT
REFERENCING NEW AS newrow FOR EACH ROW
BEGIN ATOMIC
IF newrow.TYPE_MVT_PK is null THEN
SET newrow.TYPE_MVT_PK = SQ_TYPE_MVT.nextval;
END IF;
END;
我尝试不使用最后的 ';' ,它继续失败。
这是我对 HSQL 的依赖:
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.8</version>
</dependency>
有任何想法吗?