【发布时间】:2020-01-17 16:09:17
【问题描述】:
我在沙发数据库中有这样的文档
{
"hostel": {
"city": {}
...
}
}
我在存储库中定义了这个查询
@Query("UPDATE #{#n1ql.bucket} SET hostel.state = $2 where hostel.id=$1 RETURNING #{#n1ql.bucket}.hostel ")
Hostel update(String entityId, String newState);
但是当我运行它时,我得到了这个错误:
org.springframework.core.convert.ConverterNotFoundException:
No converter found capable of converting from type [java.util.LinkedHashMap<?, ?>] to type [com.model.Hostel]
以及旅馆类型:
@Data
@Builder
@AllArgsConstructor
@JsonInclude(NON_NULL)
@EqualsAndHashCode
public class Hostel {
private @NotNull String id;
private @NotNull String city;
private JsonObject commodities;
}
我也试过了:
@Query("UPDATE #{#n1ql.bucket} SET hostel.state = $2 where hostel.id=$1 RETURNING #{#n1ql.bucket}.hostel ")
void update(String entityId, String newState);
但后来我得到了错误:
org.springframework.data.couchbase.core.CouchbaseQueryExecutionException: Query returning a primitive type are expected to return exactly 1 result, got 0
【问题讨论】:
-
你用过
@Modifying(clearAutomatically = true) -
在 org.springframework.data.couchbase.core.query 包中不可用。
-
问题出在返回值
Hostel,因为从Spring的反序列化器的角度来看,像"name: {"key": value}"这样的结构是Map。所以首先检查你的实体类Hostel是否有正确注释的类和属性。作为一个案例,您可以创建自己的反序列化器 -
@Sandro Rey 请将
@Field注释添加到hostel 的属性以及Bucket实体中的hostel 属性。 Example
标签: java spring-boot couchbase spring-data-couchbase couchbase-java-api