inmemdb-maven-plugin和maven-failsafe-plugin数据库表创建问题

时间:2015-07-13 09:55:39

标签: java maven integration-testing maven-failsafe-plugin

努力让我的集成测试与inmemdb-maven-plugin和maven-failsafe-plugin一起使用。

基本上,我运行hibernate4-maven-plugin,使用" create"生成一个SQL脚本。我需要运行集成测试的表的语句。 (使用带有inmemdb-maven-plugin的SQL脚本很简单,文档因此我不会详细说明)。我将inmemdb-maven-plugin指向生成的脚本,它会显示它没有问题:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
[INFO] Started embedded Derby database
[INFO] Server has been started
[INFO] Executing initialization scripts and loading data sets
[INFO] Loading Script[target/schema.sql]

但是,当maven-failsafe-plugin执行集成测试时,似乎没有表可用:

Caused by: java.sql.SQLException: Table/View 'MY_TEST_TABLE' does not exist.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
    ... 71 more
Caused by: ERROR 42X05: Table/View 'MY_TEST_TABLE' does not exist.
    at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
    at org.apache.derby.impl.sql.compile.DMLModStatementNode.verifyTargetTable(Unknown Source)
    at org.apache.derby.impl.sql.compile.InsertNode.bindStatement(Unknown Source)
    at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
    at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
    at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
    ... 65 more

为了确认是这种情况,我复制了创建MY_TEST_TABLE的SQL部分,将其添加为本机查询:

Query query = em.createNativeQuery( "create table my_test_table (" +
         "   id bigint generated by default as identity, "+
         "   some_field bigint, " +
         "   another_field varchar(255), " +
         "   primary key (id) )");

query.executeUpdate();

// Rest of integration test class

然后错误就消失了,因为现在MY_TEST_TABLE可用了。

所以,我坦率地难倒。如何让两个插件都能很好地播放?我很感激任何意见和/或,谢谢。

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。修复此问题的方法是将我的连接网址从jdbc:h2:mem:picnicwms更改为jdbc:h2:tcp://localhost:9092/mem:picnicwms