我可以使用Morphia轻松地将Java对象插入MongoDb数据库。现在,我想检索文档并将其映射为java对象。 MongoDB文档是这样的:
{
"Name":"XXX",
"Fingertemplate":{ "immutable" : { "size" : { "x" : 388 , "y" : 374} , "minutiae" : [ ........
我的示例代码如下所示:
@Entity(value="fingertable", noClassnameStored=true)
public class RecordFingerTemplate {
@Id private ObjectId id;
@Property private String name;
@Embedded private FingerprintTemplate fingertemp;
public RecordFingerTemplate (){
}
public RecordFingerTemplate(String name)
{
this.name=name;
}
public ObjectId getId() {
return id;
}
protected void setId( final ObjectId id ) {
this.id = id;
}
public FingerprintTemplate getTemplate(){
return fingertemp;
}
public void setTemplate(FingerprintTemplate template){
this.fingertemp=fingertemp;
}
}
并将对象保存到我正在使用datastore.save(Object)
的数据库中,它可以完美地工作现在,我想检索文档并获取指纹模板对象。
List<RecordFingerTemplate> result=datastore.createQuery(RecordFingerTemplate.class)
.field("name").containsIgnoreCase("john")
.order("name")
.asList();
错误:** org.mongodb.morphia.mapping.MappingException:错误设置来自转换器(PassthroughConverter)的ImmutableTemplate.size值到{“ x”:388,“ y ......... **
尝试将@Embedded
注释移动/添加到FingerprintTemplate
,并在您的类型上显式调用map()
。惰性映射有一些空白,恐怕您可能会漏掉这种情况。