开发者

Why does grails use hsqldb when I ask for mysql?

开发者 https://www.devze.com 2022-12-25 00:30 出处:网络
I\'m following the racetrack example from Jason Rudolph\'s book at InfoQ, using grails-1.2.1. I got up to the part where I was to switch from hsqldb to mysql. I think I\'ve deleted every reference to

I'm following the racetrack example from Jason Rudolph's book at InfoQ, using grails-1.2.1. I got up to the part where I was to switch from hsqldb to mysql. I think I've deleted every reference to hsqldb in the DataSource.groovy file, but I get an exception and the stack trace shows it's still using 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_c开发者_如何学Golass='net.sf.ehcache.hibernate.EhCacheProvider'
}
// environment specific settings
environments {
    development {
    }
    test {
    }
    production {
    }
}

When I grails run-app it all starts up with no errors. I can navigate to the home page. But when I click on one of the links, I get a stack trace:

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)

My mysql database shows no tables created. (I don't think groovy's connected to mysql yet.)

Things I've checked:

  1. mysql-connector-java-5.1.6.jar is in lib directory.
  2. I've tried grails clean
  3. I tried putting the dataSource info in the development environment (I haven't graduated to test or prod yet), but it seemed to make no difference. The stdout shows I'm using development env.

I've googled for solutions, but the only solution I've found is when people don't change the test or production environments.


Problem was the type declarations. Instead of

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 
}

should have had:

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

Found the answer in the 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 


That book is way out of date and InfoQ should pull it or add a link to the 2nd edition which came out recently and is based on Grails 1.2: http://www.infoq.com/minibooks/grails-getting-started

0

精彩评论

暂无评论...
验证码 换一张
取 消