Grails2和mongodb不工作
我正在使用Grails2.2.0和MongoDB。我已经将Grails配置为针对MongoDB而不是默认的H2内存数据库运行。从错误消息中,h2似乎与此有关,尽管我认为已将其删除 My DataSource.groovy:Grails2和mongodb不工作,mongodb,grails,runtime-error,Mongodb,Grails,Runtime Error,我正在使用Grails2.2.0和MongoDB。我已经将Grails配置为针对MongoDB而不是默认的H2内存数据库运行。从错误消息中,h2似乎与此有关,尽管我认为已将其删除 My DataSource.groovy: grails { mongo { host = "localhost" port = 27017 databaseName = "physicians" } } My BuildConfig.gr
grails {
mongo {
host = "localhost"
port = 27017
databaseName = "physicians"
}
}
My BuildConfig.groovy:
plugins {
runtime ":hibernate:$grailsVersion"
runtime ":jquery:1.8.0"
runtime ":resources:1.1.6"
// Uncomment these (or add new ones) to enable additional resources capabilities
//runtime ":zipped-resources:1.0"
//runtime ":cached-resources:1.0"
//runtime ":yui-minify-resources:0.1.4"
build ":tomcat:$grailsVersion"
runtime ":database-migration:1.1"
compile ':cache:1.0.0'
compile ':mongodb:1.1.0.GA'
}
当我想要保存域对象艺术家时,我得到的错误是:
| Error 2013-01-03 22:33:18,881 [http-bio-9090-exec-1] ERROR util.JDBCExceptionReporter - Table "ARTIST" not found; SQL statement:
insert into artist (id, version, artist_name, birth_name) values (null, ?, ?, ?) [42102-164]
| Error 2013-01-03 22:33:19,050 [http-bio-9090-exec-1] ERROR errors.GrailsExceptionResolver - JdbcSQLException occurred when processing request: [GET] /musicstack/artist/
Table "ARTIST" not found; SQL statement:
insert into artist (id, version, artist_name, birth_name) values (null, ?, ?, ?) [42102-164]. Stacktrace follows:
Message: Table "ARTIST" not found; SQL statement:
insert into artist (id, version, artist_name, birth_name) values (null, ?, ?, ?) [42102-164]
Line | Method
->> 329 | getJdbcSQLException in org.h2.message.DbException
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 169 | get in ''
| 146 | get . . . . . . . . in ''
| 4753 | readTableOrView in org.h2.command.Parser
| 4731 | readTableOrView . . in ''
| 954 | parseInsert in ''
| 375 | parsePrepared . . . in ''
| 279 | parse in ''
| 251 | parse . . . . . . . in ''
| 217 | prepareCommand in ''
| 415 | prepareLocal . . . in org.h2.engine.Session
| 364 | prepareCommand in ''
| 1121 | prepareCommand . . in org.h2.jdbc.JdbcConnection
| 71 | <init> in org.h2.jdbc.JdbcPreparedStatement
| 267 | prepareStatement . in org.h2.jdbc.JdbcConnection
| 1051 | prepareStatement in ''
| 508 | prepareStatement . in org.apache.commons.dbcp.DelegatingConnection
| 400 | prepareStatement in org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
| 7 | index . . . . . . . in musicstack.ArtistController
| 195 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter . . . . . in grails.plugin.cache.web.filter.AbstractFilter
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run . . . . . . . . in ''
^ 680 | run in java.lang.Thread
从BuildConfig.groovy
当我这么做的时候,我得到了这个:
| Error Fatal error during compilation org.apache.tools.ant.BuildException:
java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
(NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
然后我拆下了线
runtime ":database-migration:1.1"
来自BuildConfig.groovy
搜索解决此问题时未找到最后一部分。这是应该做的吗
/Lasse您已经卸载了hibernate,因此需要另一个关于mongodb的插件。 你可以加一行
compile ':mongodb:1.0.0.GA'
从BuildConfig.groovy而不是
runtime ":hibernate:$grailsVersion"
要在项目中单独使用mongodb gorm,需要注释掉
compile ':cache:1.0.0'
在BuildConfig中,因为缓存插件依赖于hibernate。您可以在以下内容中找到它:
我不得不从application.properties中删除Hibernate插件,它才能工作。我不确定为什么在应用程序中配置hibernate插件。属性这是正确答案。仅仅删除compile“:cache:1.0.0”并不能完成这项工作,但添加下一个操作将完成这项工作。
compile ':cache:1.0.0'
plugins {
....
runtime(":hibernate:$grailsVersion") {
export = false
}
....
}