Home > Uncategorized > H2 Database alternative to commit

H2 Database alternative to commit

February 24th, 2010

So the earlier post on H2 suggested adding commit to the sql statements to make the tests more reliable.

After a little more research it would appear that there is another setting you may need to apply to H2 to make it run the way you need. By default H2 in memory databases will be wiped out if there are no more connections to them. This means that if you remove all connections to an in memory database and then create a new one it will be connecting to a brand new, empty, in memory database.

How to fix it?

You can add ;DB_CLOSE_DELAY=-1 to the end of the testDatabaseName field in you spring datasource bean.

This means that the in memory database will be contained for the life of the running JVM. You can alternatively set it to a number greater than 0 and the database will be maintained for that many seconds past the last connection. This may be an alternative if you want the database to be available for a limited period only.


Categories: Uncategorized Tags:
Comments are closed.