2012-04-07 18 views
1

私のinbuiltデータベースを "update"に設定できません。 「create-drop」のように、アプリを終了すると常にクリアされます。Grails - inbuiltデータベースを "更新"に設定できません

私はMySQLデータベースを使用していて、SQLデータベースを設定する方法がわからない友人やTomcatなどとプロジェクトを共有できるように、内蔵データベースに戻ってきたことを知っておくと便利ですサーバ。すべてのヘルプは大歓迎

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

は、ここに私のDataSource.groovyファイルです。 ありがとうございます。

答えて

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' –

+0

ありがとうございました。それは期待どおりに動作します。 –

関連する問題