I am unable to set my inbuilt database to “update“.
It is always cleared when I leave the app, as if still on ‘create-drop‘.
It may be useful to know that I was using a MySQL database, and reverted back to in-built database to be able to share the project with some friends whom will not know how to set a SQL database, or a Tomcat server.
Here is my DataSource.groovy file:
dataSource {
pooled = true
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:h2:mem:myAppDevDb;MVCC=TRUE"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:h2:mem:myAppTestDb;MVCC=TRUE"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:h2:myAppProdDb;MVCC=TRUE"
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
}
}
Any help greatly appreciated.
Thanks in advance.
The problem is that your datasource is configured as an in memory datasource so it is discarded when the jvm exits. If you configure your H2 URL to use a file instead you should be able to save the database.