我是Grails的新手。我面临一个非常令人讨厌的问题。 为什么我的grails应用在每次重新启动时都会重置所有表数据。 例如,我有Post域类。当我创建一些数据时,它将保存在我的数据库中。但是当我再次重新启动我的应用程序时。所有行均被重置。我不知道为什么会这样。
检查我的DataSource.groovy ...
dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
}
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:mysql://localhost:3306/blog?useUnicode=yes&characterEncoding=UTF-8"
username = "root"
password = ""
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://localhost:3306/blog?useUnicode=yes&characterEncoding=UTF-8"
username = "root"
password = ""
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://localhost:3306/blog?useUnicode=yes&characterEncoding=UTF-8"
username = "root"
password = ""
}
}
}
我正在localhost:8080(开发环境)上测试我的应用程序。请澄清这个问题。
最佳答案
得到它了...
我从这里更改我的DataSource.groovy
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:mysql://localhost:3306/blog?useUnicode=yes&characterEncoding=UTF-8"
username = "root"
password = ""
}
}
至
development {
dataSource {
dbCreate = "validate" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:mysql://localhost:3306/blog?useUnicode=yes&characterEncoding=UTF-8"
username = "root"
password = ""
}
}
这个对我有用... :)
关于grails - 每次重新启动应用程序时,将Grails MySQL数据库重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17585594/