h2 database test maven
THis situation occurs when you configure connection to your in-memory H2 DB by default, for example: dbc:h2:mem:test
In that case DB exist until he has at least one active connection. When last connection closed, DB also closed. Depends of what you use/re-use connection (maybe pooling) and running test delays, you can get racing conditions and get unexpected results.
It can be fixed with connection parameter DB_CLOSE_DELAY=-1
, what mean db was closed only when VM died.
This is helphul link http://www.h2database.com/html/features.html#closing_a_database
I know it's too late for you to answer your question. Probably this might help.
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="org.h2.Driver" /> <property name="url" value="jdbc:h2:mem:testdb;INIT=create schema if not exists test\;runscript from 'classpath:scripts/sample.sql';**DB_CLOSE_DELAY=-1**"/>
in addition to it try to add below properties
<prop key="hibernate.hbm2ddl.auto">create</prop> <prop key="hibernate.connection.release_mode">auto</prop>
which will create schema every time server starts and drop when done.