Grails gorm查询不能与mongodb一起使用

时间:2015-06-24 06:41:40

标签: java mongodb grails groovy

我用过

在BuildConfig.groovy

compile ":mongodb:3.0.3"

在DataSource.groovy

development {
    grails {
    mongo {
        host = "localhost"
        port = 27017
        username = ""
        password = ""
        databaseName = "testProject_dev"
    }
    }
    dataSource {
    dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
    url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
    }
}

我有一个域名:Address.groovy

class Address {

    ObjectId id
    String city
    String contactNumber
    String country
    String name
    String state

    Date dateCreated
    Date lastUpdated

}

在BootStrap中

List<Address> addressList = Address.list()

在Monogo Db,我检查了db.address.find();

{
    "_id": ObjectId("553cbec3e4b0eee8a02f0645"),
    "city": "Gurgaon",
    "contactNumber": "12345678",
    "country": "India",
    "dateCreated": ISODate("2015-04-26T10:32:35.909Z"),
    "identifier": "A",
    "isActive": true,
    "isDefault": true,
    "lastUpdated": ISODate("2015-06-14T09:01:36.864Z"),
    "name": "Gurgaon 123",
    "state": "Haryana",
    "version": NumberLong(279)
}

{
    "_id": ObjectId("55429736e4b0cii7794cf"),
    "city": "Gurgaon",
    "contactNumber": "123456",
    "country": "India",
    "dateCreated": ISODate("2015-04-30T20:57:26.891Z"),
    "identifier": "B",
    "isActive": true,
    "isDefault": false,
    "lastUpdated": ISODate("2015-06-13T06:56:33.107Z"),
    "name": "Gurgaon Cyber City",
    "state": "Haryana",
    "version": NumberLong(11)
}

{
    "_id": ObjectId("557c57aee4b2uuu2342347"),
    "city": "Delhi",
    "contactNumber": "888754",
    "country": "India",
    "dateCreated": ISODate("2015-06-09T16:35:21.193Z"),
    "identifier": "C",
    "isActive": true,
    "isDefault": false,
    "lastUpdated": ISODate("2015-06-14T09:01:17.914Z"),
    "name": "Delhi Kalkaji",
    "state": "Delhi",
    "version": NumberLong(10)
}

但是当我试图运行这个项目时,它给了我一个错误:

2015 - 06 - 24 11: 36: 42, 545 + 0530 ERROR GrailsContextLoaderListener: 213 - Error initializing the application: null
java.lang.NullPointerException

at org.grails.datastore.mapping.mongo.query.MongoQuery.executeQuery(MongoQuery.java: 833)
at org.grails.datastore.mapping.query.Query.list(Query.java: 542)
at org.grails.datastore.gorm.GormStaticApi$_list_closure18.doCall(GormStaticApi.groovy: 419)

at org.grails.datastore.mapping.core.DatastoreUtils.execute(DatastoreUtils.java: 302)
at org.grails.datastore.gorm.AbstractDatastoreApi.execute(AbstractDatastoreApi.groovy: 37)

at org.grails.datastore.gorm.GormStaticApi.list(GormStaticApi.groovy: 418)
at BootStrap$_closure1.doCall(BootStrap.groovy: 18)

at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java: 327)
at grails.util.Environment.executeForEnvironment(Environment.java: 320)
at grails.util.Environment.executeForCurrentEnvironment(Environment.java: 296)
at java.util.concurrent.FutureTask.run(FutureTask.java: 266)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java: 1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java: 617)
at java.lang.Thread.run(Thread.java: 745)

但有趣的是,同一个项目正在另一台机器上运行,意味着相同的代码正在另一台笔记本电脑上工作。

请帮我找到这个,我的系统有什么问题,以及如何运行这个项目。

提前致谢。

0 个答案:

没有答案