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

huangapple go评论146阅读模式
英文:

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

问题

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

  1. 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

仓库类:

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

DTO类:

  1. @Data
  2. @Document
  3. public class ResponseDto implements Serializable {
  4. @Field("doc_type_version")
  5. private String docTypeVersion;
  6. }

文档如下:

  1. {
  2. "_class": "tr.gov.gib.efatura.core.entity.couchbase.ThreadProcessCouchbaseEntity",
  3. "calc_hash": "6DB58D42B042F975A7E68464C8E18FE5",
  4. "client": "10.233.92.0",
  5. "doc_date_time": "2023-08-09T19:24:53",
  6. "doc_type": "SYSTEMENVELOPE",
  7. "doc_type_version": "1.2",
  8. "error": "ZARF_BASARIYLA_ISLENDI",
  9. "issue_date": "2023-08-09",
  10. "gib_elements": [
  11. {
  12. "element_type": "APPLICATIONRESPONSE",
  13. "fKey": "20548227-BDB9-4A7E-B873-FB7B8E3E2BCB",
  14. "item_count": 1,
  15. "oid": "31ll52grm01001"
  16. }
  17. ],
  18. "header_version": "1.0",
  19. "state_code": "1200",
  20. "zip_path": "20548227-BDB9-4A7E-B873-FB7B8E3E2BCB.zip"
  21. }

元数据如下:

  1. {
  2. "meta": {
  3. "id": "20548227-BDB9-4A7E-B873-FB7B8E3E2BCB",
  4. "rev": "1178-177a01ea20e300000000000002000000",
  5. "expiration": 0,
  6. "flags": 33554432,
  7. "type": "json"
  8. },
  9. "xattrs": {}
  10. }

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

英文:

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.

  1. 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:

  1. @Repository
  2. @Scope(&quot;efatura_islem&quot;)
  3. @Collection(&quot;gib_thread_process_non_verified&quot;)
  4. public interface ThreadProcessCouchbaseRepository extends CouchbaseRepository&lt;ThreadProcessCouchbaseEntity, String&gt; {
  5. @Query(&quot;SELECT meta(gtp).id AS __id , gtp.doc_type_version FROM gib_thread_process_non_verified AS gtp WHERE gtp.zip_path=$documentInstanceIdentifier&quot;)
  6. ResponseDto selectApplicationResponseInfo(String documentInstanceIdentifier);
  7. }

DTO class:

  1. @Data
  2. @Document
  3. public class ResponseDto implements Serializable {
  4. @Field(&quot;doc_type_version&quot;)
  5. private String docTypeVersion;
  6. }

Document is below that:

  1. {
  2. &quot;_class&quot;: &quot;tr.gov.gib.efatura.core.entity.couchbase.ThreadProcessCouchbaseEntity&quot;,
  3. &quot;calc_hash&quot;: &quot;6DB58D42B042F975A7E68464C8E18FE5&quot;,
  4. &quot;client&quot;: &quot;10.233.92.0&quot;,
  5. &quot;doc_date_time&quot;: &quot;2023-08-09T19:24:53&quot;,
  6. &quot;doc_type&quot;: &quot;SYSTEMENVELOPE&quot;,
  7. &quot;doc_type_version&quot;: &quot;1.2&quot;,
  8. &quot;error&quot;: &quot;ZARF_BASARIYLA_ISLENDI&quot;,
  9. &quot;issue_date&quot;: &quot;2023-08-09&quot;,
  10. &quot;gib_elements&quot;: [
  11. {
  12. &quot;element_type&quot;: &quot;APPLICATIONRESPONSE&quot;,
  13. &quot;fKey&quot;: &quot;20548227-BDB9-4A7E-B873-FB7B8E3E2BCB&quot;,
  14. &quot;item_count&quot;: 1,
  15. &quot;oid&quot;: &quot;31ll52grm01001&quot;
  16. }
  17. ],
  18. &quot;header_version&quot;: &quot;1.0&quot;,
  19. &quot;state_code&quot;: &quot;1200&quot;,
  20. &quot;zip_path&quot;: &quot;20548227-BDB9-4A7E-B873-FB7B8E3E2BCB.zip&quot;
  21. }

And metadata is below that:

  1. {
  2. &quot;meta&quot;: {
  3. &quot;id&quot;: &quot;20548227-BDB9-4A7E-B873-FB7B8E3E2BCB&quot;,
  4. &quot;rev&quot;: &quot;1178-177a01ea20e300000000000002000000&quot;,
  5. &quot;expiration&quot;: 0,
  6. &quot;flags&quot;: 33554432,
  7. &quot;type&quot;: &quot;json&quot;
  8. },
  9. &quot;xattrs&quot;: {}
  10. }

答案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).

huangapple
  • 本文由 发表于 2023年8月10日 19:47:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76875458.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定