51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

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

英文:

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

问题 {#heading}

在尝试使用DTO类选择Couchbase文档的某个部分时,出现以下错误:

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
@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类:

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

文档如下:

{
  "_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"
}

元数据如下:

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

以上是您提供的翻译部分。 英文:

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&lt;ResponseDto&gt; and getting from Optional class but did not fixed.I dont understand why it look for &#39;docTypeVersion&#39; 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(&quot;efatura_islem&quot;)
@Collection(&quot;gib_thread_process_non_verified&quot;)
public interface ThreadProcessCouchbaseRepository extends CouchbaseRepository&lt;ThreadProcessCouchbaseEntity, String&gt; {

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



`}
`

DTO class:

@Data
@Document
public class ResponseDto implements Serializable {

    @Field(&amp;quot;doc_type_version&amp;quot;)
    private String docTypeVersion;



`}
`

Document is below that:

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

And metadata is below that:

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

答案1 {#1}

得分: 1

"org.springframework.dao.InvalidDataAccessApiUsageException: 类 java.util.Optional 找不到所需的属性 docTypeVersion;嵌套异常是 java.lang.IllegalStateException: 类 java.util.Optional 找不到所需的属性 docTypeVersion"

堆栈跟踪总是有用的 - 它可能会揭示框架为什么认为结果应该是一个 Optional。

此外,查询方法应该返回 List/Iterator/Optional 吗?以防没有匹配结果或有多个匹配结果?也许框架假设如果您只指定了 DTO,那么就应该返回 Optional (纯粹是猜测)。 英文:

"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"

The stack trace is always useful - it might shed some insight into why the framework thinks the result should be an Optional.

Also - shouldn't the query methods return a List/Iterator/Optional? In case there is zero (or more than one) matching results? Maybe the framework assumes Optional<DTO> if you have specified just DTO (just speculating).


赞(1)
未经允许不得转载:工具盒子 » org.springframework.dao.InvalidDataAccessApiUsageException: Required property docTypeVersion not found for class java.util.Optional