找不到java.lang.Object的映射元数据-Couchbase [英] No mapping metadata found for java.lang.Object - Couchbase
问题描述
我将实体保留在CouchBase存储库中,并尝试对其进行查询.实体看起来像这样:
I'm persisting an entity in a CouchBase repository and trying to query it. The entity looks like this:
@Document(expiry = 0)
public class GsJsonStore implements Serializable {
private static final long serialVersionUID = 7133072282172062535L;
@Id @GeneratedValue(strategy=GenerationType.AUTO)
private long id;
@Field
private Map<String,Object> _object;
@Field
private String _subject;
@Field
private String _predicate;
//Getters and Setters
}
我正在使用CouchbaseOperations模板上的N1QL查询来查询实体,如下所示:
I'm querying the entity by using N1QL queries on the CouchbaseOperations template like this:
String query1 = "SELECT META(default).id as _ID, META(default).cas as _CAS, default.* FROM default WHERE "+key+"="+"'"+value+"'";
List<GsJsonStore> list = operations.findByN1QL(N1qlQuery.simple(query1), GsJsonStore.class);
我正在_object Map中查询K-V对.我收到错误消息:No mapping metadata found for java.lang.Object
I'm querying for a K-V pair within the _object Map. I get an error : No mapping metadata found for java.lang.Object
为什么会这样?此外,我在Couchbase中将json对象存储为Map<String,Object>
,我尝试使用jackson JsonNode
类型,但是该对象还存储了与类相关的元数据.有没有更好的数据类型来表示json类型?
Why is this happening? Also, I'm storing a json object as Map<String,Object>
in Couchbase, I tried using the jackson JsonNode
type but the object was also storing class related metadata. Is there a better datatype to represent the json type?
编辑
存储在Couchbase中的数据:
Data stored in Couchbase :
{
"_object" : {
"Name" : "Kapil",
"Age" : {
"Nested" : 21
}
},
"_subject" : "Subject",
"_predicate" : "Predicate"
}
我要查找的键是_object.名称和值是"Kapil"
The key I'm looking for is _object.Name and value is 'Kapil'
推荐答案
如此处您应该覆盖默认的SPMappingCouchbaseConverter.
As explained here you should override the default SPMappingCouchbaseConverter.
这是我解决问题的方法:
Here is how I solved the problem:
@Bean
public MappingCouchbaseConverter mappingCouchbaseConverter() throws Exception {
return new MyMappingCouchbaseConverter(couchbaseMappingContext());
}
private class MyMappingCouchbaseConverter extends MappingCouchbaseConverter {
MyMappingCouchbaseConverter(MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> mappingContext) {
super(mappingContext);
}
@Override
@SuppressWarnings("unchecked")
protected <R> R read(final TypeInformation<R> type, final CouchbaseDocument source, final Object parent) {
if (Object.class == typeMapper.readType(source, type).getType()) {
return (R) source.export();
} else {
return super.read(type, source, parent);
}
}
}
这篇关于找不到java.lang.Object的映射元数据-Couchbase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!