javaspring-bootcouchbasesql++spring-data-couchbase

org.springframework.dao.InvalidDataAccessApiUsageException: Required property docTypeVersion not found for class java.util.Optional


When i try to select some part of couchbase document using a dto class,getting this error. I tried several possible solutions like changing return type of query method Optional<ResponseDto> and getting from Optional class but did not fixed.I dont understand why it look for 'docTypeVersion' in Optional class.I did not try to get docTypeVersion from Optional class.

org.springframework.dao.InvalidDataAccessApiUsageException: Required property docTypeVersion not found for class java.util.Optional; nested exception is java.lang.IllegalStateException: Required property docTypeVersion not found for class java.util.Optional 

Repository class:

@Repository
@Scope("efatura_islem")
@Collection("gib_thread_process_non_verified")
public interface ThreadProcessCouchbaseRepository extends CouchbaseRepository<ThreadProcessCouchbaseEntity, String> {

    @Query("SELECT meta(gtp).id AS __id , gtp.doc_type_version FROM gib_thread_process_non_verified AS gtp WHERE gtp.zip_path=$documentInstanceIdentifier")
    ResponseDto selectApplicationResponseInfo(String documentInstanceIdentifier);
}

DTO class:

@Data
@Document
public class ResponseDto implements Serializable {
   
    @Field("doc_type_version")
    private String docTypeVersion;
}

Document is below that:

{
  "_class": "tr.gov.gib.efatura.core.entity.couchbase.ThreadProcessCouchbaseEntity",
  "calc_hash": "6DB58D42B042F975A7E68464C8E18FE5",
  "client": "10.233.92.0",
  "doc_date_time": "2023-08-09T19:24:53",
  "doc_type": "SYSTEMENVELOPE",
  "doc_type_version": "1.2",
  "error": "ZARF_BASARIYLA_ISLENDI",
  "issue_date": "2023-08-09",
  "gib_elements": [
    {
      "element_type": "APPLICATIONRESPONSE",
      "fKey": "20548227-BDB9-4A7E-B873-FB7B8E3E2BCB",
      "item_count": 1,
      "oid": "31ll52grm01001"
    }
  ],
 
  "header_version": "1.0",
  "state_code": "1200",
  "zip_path": "20548227-BDB9-4A7E-B873-FB7B8E3E2BCB.zip"
}

And metadata is below that:

{
  "meta": {
    "id": "20548227-BDB9-4A7E-B873-FB7B8E3E2BCB",
    "rev": "1178-177a01ea20e300000000000002000000",
    "expiration": 0,
    "flags": 33554432,
    "type": "json"
  },
  "xattrs": {}
}

Solution

  • I had the same problem as you and making the return type optional did not work for me. Making it List works, however when you know that you are selecting a unique document, you dont want to retrieve in a list. You are using the entity class in your repo and trying to retrieve it as a dto. One solution is, make repo use your dto class. Modify it like this:

    @Repository
    @Scope("efatura_islem")
    @Collection("gib_thread_process_non_verified")
    public interface ThreadProcessCouchbaseRepository extends CouchbaseRepository< ResponseDto, String> {
    
        @Query("SELECT meta(gtp).id AS __id , gtp.doc_type_version FROM gib_thread_process_non_verified AS gtp WHERE gtp.zip_path=$documentInstanceIdentifier")
        ResponseDto selectApplicationResponseInfo(String documentInstanceIdentifier);
    }
    

    If you dont want to modify your repo, or write a seperate one for the dto, you should make your dto extend the entity class like this:

    @Data
    @Document
    public class ResponseDto extends ThreadProcessCouchbaseEntity {...}
    

    Then you will not need to use Optional or List. It worked for me, i hope this works for you too.