Java 必须为此操作提供PartitionKey值

Java 必须为此操作提供PartitionKey值,java,azure-cosmosdb,azure-cosmosdb-sqlapi,Java,Azure Cosmosdb,Azure Cosmosdb Sqlapi,我正在尝试从Azure Cosmos Db集合检索文档。我遇到了一个错误 Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.UnsupportedOperationException: PartitionKey value must be supplie

我正在尝试从Azure Cosmos Db集合检索文档。我遇到了一个错误

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 cause
java.lang.UnsupportedOperationException: PartitionKey value must be supplied for this operation.
我试图在线查找如何为函数findById()提供分区键值,但“Azure Spring data cosmosdb”似乎没有为java实现提供分区键值的选项

orderTransactionRepository.findById("id").get
搜索的主页中提到的分区集合的findById方法的

相反,您可以通过自定义查询按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);
//正确,postalCode是地址域中的ID字段
@存储库
公共接口AddressRepository扩展了DocumentDbRepository



总结一下,基本上是由于SpringDataCommons更改了querylookupstrategy实现的接口名称。您需要返回到以前版本的
cosmos db,即2.0.5
!下面的链接说明了问题github.com/Microsoft/spring data cosmosdb/issues/304

我尝试使用自定义查询,但再次遇到错误“自定义查询方法必须有策略”。我尝试使用@query annotation创建一个查询,但它适用于Jpa存储库,而不适用于DocumentDb。你能告诉我哪个注释可以解决这个问题吗?我找出了错误,基本上是因为SpringDataCommons更改了querylookupstrategy实现的接口名。回到之前版本的cosmos db,即2.0.5。我能解决这个问题!这是一个链接,说明了这个问题@NikhilJain。非常感谢您的分享,我总结了您的解决方案,供论坛上的其他人参考。非常感谢。
// Incorrect for partitioned collection, exception will be thrown
   Address result = repository.findById(id);  // Caution: Works for non-partitioned collection
// 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);