我正在使用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了。)
我检查过的事情:
grails clean
我已经搜索了解决方案,但我发现的唯一解决方案是当人们不改变测试或生产环境时。
答案 0 :(得分: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
}
应该有:
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中找到答案:
配置DataSource时,在任何配置设置之前不要包含type或def关键字,因为Groovy会将这些视为局部变量定义,并且不会处理它们。例如,以下内容无效:
boolean pooled = true
答案 1 :(得分:1)
这本书已经过时了,InfoQ应该提取它或添加最近出版的第2版的链接,它基于Grails 1.2:http://www.infoq.com/minibooks/grails-getting-started