当我要求mysql时,为什么grails使用hsqldb?

Joh*_*ohn 0 grails datasource

我正在使用Grails-1.2.1 跟踪Jason Rudolph在InfoQ上的书中的赛道示例.我到了我要从hsqldb切换到mysql的部分.我想我已经删除了DataSource.groovy文件中对hsqldb的每个引用,但是我得到了一个异常,堆栈跟踪显示它仍在使用hsqldb.

DataSource.groovy的

dataSource {
    boolean pooled = true
    String driverClassName = "com.mysql.jdbc.Driver"
    String url = "jdbc:mysql://localhost/dfpc2"
    String dbCreate = "create"
    String username = "dfpc2"
    String password = "dfpc2"
    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 {
    }
    test {
    }
    production {
    }
}
Run Code Online (Sandbox Code Playgroud)

当我grails run-app全部启动没有错误.我可以导航到主页.但是当我点击其中一个链接时,我得到一个堆栈跟踪:

java.sql.SQLException: Table not found in statement [select this_.id as id0_0_, this_.version as version0_0_, this_.name as name0_0_, this_.variant as variant0_0_ from domainObject this_ limit ?]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at dfpc2.domainObjectController$_closure2.doCall(script1269434425504953491149.groovy:13)
at dfpc2.domainObjectController$_closure2.doCall(script1269434425504953491149.groovy)
at java.lang.Thread.run(Thread.java:619)
Run Code Online (Sandbox Code Playgroud)

我的mysql数据库显示没有创建表.(我不认为groovy已经连接到mysql了.)

我检查过的事情:

  1. mysql-connector-java-5.1.6.jar位于lib目录中.
  2. 我试过了 grails clean
  3. 我尝试将dataSource信息放在开发环境中(我还没有毕业测试或生产),但似乎没有任何区别.stdout显示我正在使用开发环境.

我已经google了解决方案,但我发现的唯一解决方案是人们不改变测试或生产环境.

Joh*_*ohn 6

问题是类型声明.代替

dataSource {
    boolean pooled = true
    String driverClassName = "com.mysql.jdbc.Driver"
    String url = "jdbc:mysql://localhost/dfpc2"
    String dbCreate = "create"
    String username = "dfpc2"
    String password = "dfpc2"
    dialect = org.hibernate.dialect.MySQL5InnoDBDialect 
}
Run Code Online (Sandbox Code Playgroud)

应该有:

dataSource {
    pooled = true
    driverClassName = "com.mysql.jdbc.Driver"
    url = "jdbc:mysql://localhost/dfpc2"
    dbCreate = "create"
    username = "dfpc2"
    password = "dfpc2"
    dialect = org.hibernate.dialect.MySQL5InnoDBDialect 
}
Run Code Online (Sandbox Code Playgroud)

在grails doco中找到答案:

配置DataSource时,在任何配置设置之前不要包含type或def关键字,因为Groovy会将这些视为局部变量定义,并且不会对它们进行处理.例如,以下内容无效:

boolean pooled = true 
Run Code Online (Sandbox Code Playgroud)