英文:
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<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(&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;)
ResponseDto selectApplicationResponseInfo(String documentInstanceIdentifier);
`}
`
DTO class:
@Data
@Document
public class ResponseDto implements Serializable {
@Field(&quot;doc_type_version&quot;)
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": {}
}
答案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).