3

I have a SpringBoot 2 app that uses using Couchbase as a database, Spring-Boot and Spring-Data and Lombok fot the getters and equals method I have created this Repository

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

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


}

and here all the objects created with Lombok library

public class BendicionesDoc<T>implements Serializable {


        @Field
        private T data;

    }

and

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

    private List<Identifier> identifier;


}

and

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

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

}

and

@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;
    }

}

But when I run the repository query I got always 0 results, even there are docs. in the DB:

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
Sandro Rey
  • 2,429
  • 13
  • 36
  • 80

1 Answers1

0

You need to define your reference type in CouchbaseRepository<T, K> then simply add the reference type Item as CouchbaseRepository<BendicionesDoc<Item>, String> and just use Repository query keywords for findById(String id).

public interface BenRepository extends CouchbaseRepository<BendicionesDoc<Item>, String> { 

    List<BendicionesDoc<Item>> findById(String id);

}
Jonathan JOhx
  • 5,784
  • 2
  • 17
  • 33