0

我想引导以下课程:

import org.bson.types.ObjectId

class Foo{  
 ObjectId id  
 String name 

}

现在在 BootStrap.groovy 我放了:

import org.bson.types.ObjectId
...
def foo = new Foo(
id: new ObjectId("507f191e810c19729de860ea"),
name: "foo"
)

但是当我想检查脚手架结果时,我收到以下错误:

Error 500: Internal Server Error

Class
    java.lang.IllegalStateException
Message
    Cannot convert value of type [java.lang.Integer] to required type [org.bson.types.ObjectId] for property 'id': no matching editors or conversion strategy found

我怎样才能显示ObjectId

4

1 回答 1

0

您可能应该为您的 Foo 类添加正确的映射(并使用分配的Stringid 而不是ObjectId类型)。例如:

class Foo{

String id
String name 

static mapping = {
    table "Foo" 
    id column: 'Id', generator: 'assigned'
    name column: "Name"
  }
}

然后在你的 Bootstrap.groovy 中:

def foo = new Foo(
    id: "507f191e810c19729de860ea",
    name: "foo"
)
foo.save();
于 2013-09-12T10:45:17.947 回答