0

我是 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 (开发环境)上测试我的应用程序。请澄清我这个问题。

4

2 回答 2

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

这个对我有用... :)

于 2013-07-11T05:33:38.477 回答
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 = ""
      }
   }
}
于 2014-03-18T08:27:05.547 回答