Bheku Msimanga
Bheku Msimanga

Reputation: 111

inmemdb-maven-plugin and maven-failsafe-plugin database table creation issue

Struggling to get my integration tests working with inmemdb-maven-plugin and maven-failsafe-plugin.

Basically, I run hibernate4-maven-plugin that generates an SQL script with the "create" statements for the tables I will need to run my integration tests. (using SQL scripts with inmemdb-maven-plugin is straightforward and document so I won't elaborate on this) . I point inmemdb-maven-plugin to the generated script, and it would appear it reads this without problem:

-------------------------------------------------------
 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]

However, when maven-failsafe-plugin executes the integration test(s), it would appear that none of the tables are available:

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

To confirm that this was the case, I copied the portion of the SQL that creates MY_TEST_TABLE, added it as a native query:

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

Then the error went away, as now MY_TEST_TABLE was available.

So, I'm stumped frankly. How do I get both plugins to play nicely? I would appreciate any input and/or, thanks.

Upvotes: 0

Views: 298

Answers (1)

scranen
scranen

Reputation: 31

I ran in to the same problem. What fixed it for me was changing my connection url from jdbc:h2:mem:picnicwms to jdbc:h2:tcp://localhost:9092/mem:picnicwms.

Upvotes: 1

Related Questions