I have a sql script which I've tested from the H2 console, no problems.
I take that same script execute it @BeforeClass of a junit test which
appears to be successful; I can then open the H2 console and query as
needed. I make sure to close this connection because it's external to my
data access class and that class will open/manage it's own connections.
When the data access class beingsto execute as part of tests I always get
a table not found error. I've read on another post in this forum
(org.h2.jdbc.JdbcSQLException:
IO Exception: "java.io.EOFException"
<https://groups.google.com/forum/#!searchin/h2-database/EOFException%7Csort:relevance/h2-database/os1Hl43LLqY/mfUdoU9h_7gJ>)
that the EOF I'm experiencing can be related to the database already being
open/read?! I have both the execution of the sql script and the data
access class set to FILE_LOCK=NO.
Am I going crazy or should this be working just fine? At any point of this
I can open the h2 console and query just fine. I often terminate the
console to ensure a lock, which sometimes seems to be hold regardless of
the FILE_LOCK option (maybe a table-level?), is not present and the
database can always be re-created. Manually deleting the create h2.db and
traces does not help either.
@BeforeClass
public static void init() throws Exception {
//clean original file(s)
if(new File(TEST_FILE_PATH + ".h2.db").delete() &&
new File(TEST_FILE_PATH + ".trace").delete());
logger.debug("old datasource files removed");
//build test database
Class.forName("org.h2.Driver");
Connection connection = DriverManager.getConnection(
"jdbc:h2:./src/test/resources/nutrition;MV_STORE=FALSE;FILE_LOCK=NO",
"sa", "");
//initialize the testing database
RunScript.execute(connection, new FileReader(new
File("./build/database.sql")));
connection.close();
//init data access layer
access = new H2DataAccess("testing");
}
I'm using mybatis for jdbc interactions...
<environment id="testing">
<transactionManager type='JDBC' />
<dataSource type='POOLED'>
<property name='driver' value='org.h2.Driver' />
<property name='url'
value='jdbc:h2:./src/test/resource/nutrition;MV_STORE=FALSE;FILE_LOCK=NO' />
<property name='username' value='sa' />
<property name='password' value='' />
</dataSource>
</environment>
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.