每次重启应用程序时,Grails都会重置MySQL数据库

时间:2013-07-11 05:22:05

标签: grails gorm

我是Grails的新人。我面临一个非常恼人的问题。 为什么我的grails app会在每次重启应用程序时重置所有表数据。例如我有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(开发环境)上测试我的应用程序。请澄清这个问题。

2 个答案:

答案 0 :(得分:1)

得到了......

我从这个

更改了我的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 = ""
    }
}

它对我有用...... :)

答案 1 :(得分:0)

我在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.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
}
// environment specific settings
environments {
    development {
      dataSource {
        dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
        url = "jdbc:mysql://localhost/blog?autoReconnect=truejdbcCompliantTruncation=false"
        username = "root"
        password = ""
      }
   }
}