grails - 每次重新启动应用程序时,将Grails MySQL数据库重置

标签 grails gorm

我是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/

相关文章:

Grails 启动两个内存数据库用于开发/测试?

java - Grails:在非抽象类中不能有抽象方法错误

grails - Grails域类中的OneToMany关联

grails - Grails的GORM约束问题

grails - 满足多个表条件

child 找到的Grails 1到n关系

jquery - grails 中带有 2 个按钮的 div

grails - UrlEncodedSlash 被 HttpFirewall 阻止(Grails 3.3.0.RC1;Spring-security-core 3.2.0.M1)

hibernate - GRAILS GORM保存 child 时如何自动更新父属性

hibernate - 基于全局条件限制从数据库检索域对象