在向azure cosmosdb启动查询时,有没有办法在Java JPA(DocumentDbRepository)中编写自定义或本机查询?

在向azure cosmosdb启动查询时,有没有办法在Java JPA(DocumentDbRepository)中编写自定义或本机查询?,java,sql,spring-data,azure-cosmosdb,Java,Sql,Spring Data,Azure Cosmosdb,已连接到azure cosmosdb并能够触发默认查询,如findAll()和findById(字符串Id)。但是我不能使用@query注释编写本机查询,因为代码没有考虑它。始终考虑respository类/接口中函数的名称。我需要一种方法来启动对azure cosmos db的自定义或本机查询 尝试使用@Query注释。但不起作用 List findBySessionID(@Param(“sessionID”)字符串sessionID); @Query(nativeQuery=true,va

已连接到azure cosmosdb并能够触发默认查询,如
findAll()
findById(字符串Id)
。但是我不能使用
@query
注释编写本机查询,因为代码没有考虑它。始终考虑respository类/接口中函数的名称。我需要一种方法来启动对azure cosmos db的自定义或本机查询

尝试使用@Query注释。但不起作用

  • List findBySessionID(@Param(“sessionID”)字符串sessionID);
    
  • @Query(nativeQuery=true,value=“SELECT*FROM MonitoringSessions M,其中M.sessionID like:sessionID”)
    列出findSessions(@Param(“sessionID”)字符串sessionID);
    
  • findBySessionID()
    正在按预期工作<代码>查找会话()不工作。下面是运行代码时出现的根错误


    原因:
    org.springframework.data.mapping.PropertyReferenceException:找不到类型监视会话的属性findSessions

    感谢您的响应。我从下面的链接中得到了我想要的。链接页面的作者获得了荣誉

    公共课程{

     private final ExecutorService executorService;
     private final Scheduler scheduler;
     private AsyncDocumentClient client;
    
     private final String databaseName = "UniversityDatabase";
     private final String collectionId = "StudentCollection";
    
     private int numberOfDocuments;
    
     public Program() {
         // public constructor
         executorService = Executors.newFixedThreadPool(100);
         scheduler = Schedulers.from(executorService);
         client = new AsyncDocumentClient.Builder().withServiceEndpoint("uri")
                 .withMasterKeyOrResourceToken("key")
                 .withConnectionPolicy(ConnectionPolicy.GetDefault()).withConsistencyLevel(ConsistencyLevel.Eventual)
                 .build();
    
     }
    
     public static void main(String[] args) throws InterruptedException, JSONException {
         FeedOptions options = new FeedOptions();
         // as this is a multi collection enable cross partition query
         options.setEnableCrossPartitionQuery(true);
         // note that setMaxItemCount sets the number of items to return in a single page
         // result
         options.setMaxItemCount(5);
         String sql = "SELECT TOP 5 s.studentAlias FROM coll s WHERE s.enrollmentYear = 2018 ORDER BY s.studentAlias";
         Program p = new Program();
         Observable<FeedResponse<Document>> documentQueryObservable = p.client
                         .queryDocuments("dbs/" + p.databaseName + "/colls/" + p.collectionId, sql, options);
         // observable to an iterator
         Iterator<FeedResponse<Document>> it = documentQueryObservable.toBlocking().getIterator();
    
         while (it.hasNext()) {
                 FeedResponse<Document> page = it.next();
                 List<Document> results = page.getResults();
                 // here we iterate over all the items in the page result
                 for (Object doc : results) {
                         System.out.println(doc);
                 }
         }
    
     }
    
    专用最终执行者服务;
    专用最终调度器;
    私有异步文件客户端;
    私有最终字符串databaseName=“UniversityDatabase”;
    私有最终字符串collectionId=“StudentCollection”;
    私人文件;
    公共计划(){
    //公共构造函数
    executorService=Executors.newFixedThreadPool(100);
    scheduler=Schedulers.from(executorService);
    client=new AsyncDocumentClient.Builder().withServiceEndpoint(“uri”)
    .使用MasterKey或ResourceToken(“密钥”)
    .withConnectionPolicy(ConnectionPolicy.GetDefault()).WithConsistenceLevel(ConsistenceLevel.Final)
    .build();
    }
    公共静态void main(字符串[]args)抛出InterruptedException、JSONException{
    FeedOptions=新的FeedOptions();
    //因为这是一个多集合的跨分区查询
    options.setEnableCrossPartitionQuery(true);
    //请注意,setMaxItemCount设置单个页面中要返回的项目数
    //结果
    选项。setMaxItemCount(5);
    String sql=“从coll s中选择前5名s.studentAlias,其中s.enrollmentYear=2018年s.studentAlias订单”;
    程序p=新程序();
    可观察文档QueryObservable=p.client
    .queryDocuments(“dbs/”+p.databaseName+“/colls/”+p.collectionId、sql、options);
    //迭代器可以观察到的
    迭代器it=documentQueryObservable.toBlocking().getIterator();
    while(it.hasNext()){
    FeedResponse page=it.next();
    列表结果=page.getResults();
    //在这里,我们迭代页面结果中的所有项
    对于(对象文档:结果){
    系统输出打印项次(doc);
    }
    }
    }
    

    }

    您使用的是Spring数据Cosmosdb,而不是Spring数据JPA,对吗?Spring Data Cosmosdb似乎没有
    查询
    注释,您不能简单地使用来自不同Spring数据模块的注释。HI@jenschauder。那么,有没有办法使用Spring data Cosmosdb编写自定义查询来从azure cosmos db获取数据?我希望正常的机制能够工作,但我从未使用过SD Cosmosdb,所以我不能确定。试一试: