gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 14:56:46 25 4
gpt4 key购买 nike

我正在使用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/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com