grails - 为什么在我要求mysql时grails使用hsqldb?

标签 grails datasource

我正在使用grails-1.2.1跟踪Jason Rudolph's book at 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 {
    }
}

当我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)

我的mysql数据库显示未创建任何表。 (我认为groovy还没有连接到mysql。)

我检查过的事情:
  • mysql-connector-java-5.1.6.jar在lib目录中。
  • 我尝试过grails clean
  • 我尝试将dataSource信息放入开发环境中(我尚未毕业来进行测试或生产),但似乎没有什么区别。标准输出显示我正在使用开发环境。

  • 我一直在寻找解决方案,但是我发现的唯一解决方案是人们无需更改测试或生产环境。

    最佳答案

    问题是类型声明。代替

    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 
    }
    

    应该有:
    dataSource {
        pooled = true
        driverClassName = "com.mysql.jdbc.Driver"
        url = "jdbc:mysql://localhost/dfpc2"
        dbCreate = "create"
        username = "dfpc2"
        password = "dfpc2"
        dialect = org.hibernate.dialect.MySQL5InnoDBDialect 
    }
    

    在grails doco中找到了答案:

    When configuring the DataSource do not include the type or the def keyword before any of the configuration settings as Groovy will treat these as local variable definitions and they will not be processed. For example the following is invalid:


    boolean pooled = true 
    

    关于grails - 为什么在我要求mysql时grails使用hsqldb?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2507742/

    相关文章:

    google-app-engine - 谷歌应用引擎上的 Grails

    grails - 阻止 Grails 在 Controller 中生成某些方法?

    java - Oracle JDBC 数据源将所有连接的自动提交属性设置为 false

    Android - 数据源与存储库

    json - grails spring 安全休息状态 401 重定向到 Controller 的操作以抛出自定义错误消息

    java - Grails 无法解决依赖关系

    grails - 对Grails应用程序进行国际化时出错

    postgresql - 将 Exposed with DataSource 与 Postgres 一起使用时不使用索引

    jms - Websphere Application Server v7 配置无需重启?