java key值_java-必须为此操作提供PartitionKey值
搜索了071000的主頁中提到的用于分區集合的findById方法的test code.
@Test
public void testFindByIdForPartitionedCollection() {
final List
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));
}
您可以找到語句here:
對于分區集合,如果要通過findById(id)查詢記錄,將引發異常.
// 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
{List
findByPostalCode(String postalCode);}
// Query
List
result = repository.findByPostalCode(postalCode);我發現另一種方法是,您仍然可以在spring-data-cosmos包中使用Document DB normal sdk,您只需要以一種簡單的方式封裝該方法.請參考此sample code.
僅作總結,基本上是由于Spring數據公共更改了querylookupstrategy正在實現的接口名稱.您需要返回到cosmos-db的先前版本,即2.0.5!這是說明問題的鏈接github.com/Microsoft/spring-data-cosmosdb/issues/304
總結
以上是生活随笔為你收集整理的java key值_java-必须为此操作提供PartitionKey值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jstl java_JSTL-Java-
- 下一篇: java session丢失_跨域造成s