【问题标题】:Spring Data for Couchbase - java.lang.IllegalArgumentException: Unsupported type for JsonArray:Couchbase 的 Spring 数据 - java.lang.IllegalArgumentException:JsonArray 不支持的类型:
【发布时间】:2020-02-12 07:14:59
【问题描述】:

我有一个 SpringBoot 2 应用程序,它使用 Couchbase 作为数据库、Spring-Boot 和 Spring-Data 以及 Lombok 的 getter 和 equals 方法 我已经创建了这个存储库

@ViewIndexed(designDoc = "bendicionesDoc")
public interface BenRepository extends CouchbaseRepository<BendicionesDoc, String> {

    @Query("#{#n1ql.selectEntity} where #{#n1ql.filter} AND ANY uuid IN data.identifier SATISFIES uuid = $1 END")
    List<BendicionesDoc<Item>> findById(Identifier identifier);


}

这里是使用 Lombok 库创建的所有对象

public class BendicionesDoc<T>implements Serializable {


        @Field
        private T data;

    }

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(NON_NULL)
public class Item {

    private List<Identifier> identifier;


}

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(NON_NULL)
@EqualsAndHashCode
public class Identifier {

    private String id;
    private MasterServant idContext;
    private MasterServant idScope;

}

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(NON_NULL)
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class MasterServant {

    private String context;
    @JsonValue
    @EqualsAndHashCode.Include
    private String value;

    private Name valueDescription;

    @JsonCreator
    public MasterServant(String value) {
        this.value = value;
    }

}

但是当我运行存储库查询时,我得到了这个错误:

java.lang.IllegalArgumentException: Unsupported type for JsonArray: class com.bendiciones.Identifier

【问题讨论】:

    标签: json spring-boot spring-data-jpa spring-data-couchbase couchbase-java-api


    【解决方案1】:

    Identifier是一个对象,不能简单的让Couchbase在N1QL中比较一个对象

    你的方法定义应该是这样的:

    @Query("#{#n1ql.selectEntity} where #{#n1ql.filter} AND ANY uuid IN data.identifier SATISFIES uuid.id = $1 END")
    List<BendicionesDoc<Item>> findById(String id);
    

    【讨论】:

      猜你喜欢
      • 2020-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 2017-09-22
      • 1970-01-01
      • 2014-10-18
      相关资源
      最近更新 更多