2012-04-07 31 views
1

我無法將我的內置數據庫設置爲「update」。 當我離開應用程序時,它總是被清除,彷彿仍在'create-drop'上。Grails - 無法將內置數據庫設置爲「更新」

知道我正在使用MySQL數據庫並恢復到內置數據庫以便能夠與一些不知道如何設置SQL數據庫或Tomcat的朋友共享項目可能很有用服務器。

這裏是我的DataSource.groovy文件:

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" 
      } 
     } 
    } 
} 

任何幫助極大的讚賞。 在此先感謝。

回答

4

問題是您的數據源被配置爲內存數據源,所以當jvm退出時它會被丟棄。如果您將H2 URL配置爲使用文件,您應該可以保存數據庫。

development { 
    dataSource { 
     dbCreate = "update" 
     url = "jdbc:h2:somefile:myAppDevDb;MVCC=TRUE" 
    } 
} 
+2

是的。請注意,使用此URL將在應用程序運行的當前工作目錄中創建文件'somefile'。使用絕對路徑可能更安全,例如'jdbc:h2:/ data/db/somefile:myAppDevDb; MVCC = TRUE'或相對於當前用戶主目錄:'jdbc:h2:〜/ somefile:myAppDevDb; MVCC = TRUE' – 2012-04-07 19:36:04

+0

非常感謝。它的行爲如預期。 – 2012-04-08 13:38:01