第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

必須為此操作提供 PartitionKey 值

必須為此操作提供 PartitionKey 值

紅顏莎娜 2022-06-15 17:31:46
我正在嘗試從 Azure Cosmos Db 集合中檢索文檔。我遇到了一個(gè)錯(cuò)誤Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.UnsupportedOperationException: PartitionKey value must be supplied for this operation.] with root causejava.lang.UnsupportedOperationException: PartitionKey value must be supplied for this operation.我試圖在網(wǎng)上查找如何為函數(shù) findById() 提供分區(qū)鍵值,但似乎“Azure Spring 數(shù)據(jù) cosmosdb”沒(méi)有為 java 函數(shù)提供分區(qū)鍵的選項(xiàng)執(zhí)行orderTransactionRepository.findById("id").get
查看完整描述

1 回答

?
Cats萌萌

TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超9個(gè)贊

搜索了spring-data-cosmos主頁(yè)中提到的分區(qū)集合findById方法的測(cè)試代碼。


@Test

    public void testFindByIdForPartitionedCollection() {

        final List<Address> addresses = repository.findByPostalCode(TestConstants.POSTAL_CODE);


        assertThat(addresses.size()).isEqualTo(2);

        assertThat(addresses.get(0).getPostalCode().equals(TestConstants.POSTAL_CODE));

        assertThat(addresses.get(1).getPostalCode().equals(TestConstants.POSTAL_CODE));

    }

你可以在這里找到這些陳述:


對(duì)于分區(qū)集合,如果要通過(guò) findById(id) 查詢記錄,會(huì)拋出異常。


// Incorrect for partitioned collection, exception will be thrown

   Address result = repository.findById(id);  // Caution: Works for non-partitioned collection

相反,您可以使用自定義查詢按 ID 字段名稱查詢記錄。


// Correct, postalCode is the ID field in Address domain

   @Repository

   public interface AddressRepository extends DocumentDbRepository<Address, String> {

      List<Address> findByPostalCode(String postalCode);

   }


   // Query

   List<Address> result = repository.findByPostalCode(postalCode);

另一種方法我發(fā)現(xiàn)你仍然可以在 spring-data-cosmos 包中使用 Document DB 普通 sdk,你只需要以簡(jiǎn)單的方式封裝該方法。請(qǐng)參考此示例代碼。


就總結(jié)而言,這基本上是由于 Spring data commons 更改了 querylookupstrategy 正在實(shí)現(xiàn)的接口名稱。你需要回到以前的版本cosmos-db i.e. 2.0.5!這是說(shuō)明問(wèn)題的鏈接 github.com/Microsoft/spring-data-cosmosdb/issues/304


查看完整回答
反對(duì) 回復(fù) 2022-06-15
  • 1 回答
  • 0 關(guān)注
  • 120 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)