[英]No converter found capable of converting from type [java.util.LinkedHashMap<?, ?>] to type
I have documents like this in a couchbase DB我在沙发数据库中有这样的文件
{
"hostel": {
"city": {}
...
}
}
and I have this query defined in a repository我在存储库中定义了这个查询
@Query("UPDATE #{#n1ql.bucket} SET hostel.state = $2 where hostel.id=$1 RETURNING #{#n1ql.bucket}.hostel ")
Hostel update(String entityId, String newState);
but when I run it I got this error:但是当我运行它时,我收到了这个错误:
org.springframework.core.convert.ConverterNotFoundException:
No converter found capable of converting from type [java.util.LinkedHashMap<?, ?>] to type [com.model.Hostel]
and the Hostel type:和旅馆类型:
@Data
@Builder
@AllArgsConstructor
@JsonInclude(NON_NULL)
@EqualsAndHashCode
public class Hostel {
private @NotNull String id;
private @NotNull String city;
private JsonObject commodities;
}
I also tried with:我也试过:
@Query("UPDATE #{#n1ql.bucket} SET hostel.state = $2 where hostel.id=$1 RETURNING #{#n1ql.bucket}.hostel ")
void update(String entityId, String newState);
but then I got the error:但后来我得到了错误:
org.springframework.data.couchbase.core.CouchbaseQueryExecutionException: Query returning a primitive type are expected to return exactly 1 result, got 0
According to Spring Data: Modifying Query根据Spring Data:修改查询
You can specify the following return types:
您可以指定以下返回类型:
void
空白
int (updated record count)
int(更新记录数)
boolean(whether a record was updated)
布尔值(记录是否更新)
In your case you have return type Hostel
what is not good if you are using SpringData
.在您的情况下,如果您使用
SpringData
您的返回类型为Hostel
是不好的。 Spring can not convert result of query execution to Hostel
type. Spring 无法将查询执行的结果转换为
Hostel
类型。 Try to use one of type specified earlier尝试使用之前指定的类型之一
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.