Orientdb:获取记录时数据库关闭异常

Orientdb : database closed exception while fetching records

正在尝试从 orientdb 获取记录。我遇到以下错误:

Exception in thread "main" com.orientechnologies.orient.core.exception.ODatabaseException: Database 'remote:localhost/testdb' is closed
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentAbstract.checkOpenness(ODatabaseDocumentAbstract.java:2328)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentRemote.fetchNextPage(ODatabaseDocumentRemote.java:446)
at com.orientechnologies.orient.client.remote.message.ORemoteResultSet.fetchNextPage(ORemoteResultSet.java:52)
at com.orientechnologies.orient.client.remote.message.ORemoteResultSet.hasNext(ORemoteResultSet.java:47)
at com.orientechnologies.orient.core.sql.executor.OResultSet.tryAdvance(OResultSet.java:41)
at java.util.Spliterator.forEachRemaining(Spliterator.java:326)
at com.orientechnologies.orient.core.sql.executor.OResultSet.forEachRemaining(OResultSet.java:49)
at aoa.services.impl.OrientdConnectionHandler.getResultList(OrientdConnectionHandler.java:197)
at aoa.services.impl.OrientdConnectionHandler.main(OrientdConnectionHandler.java:209)

使用以下代码查询数据:

   ...
    try(ODatabaseSession ses_orient = getConnPool(dbnae).acquire();){
      rs = ses_orient.query(query);  
    }


    public ODatabasePool getConnPool(String dbname){
      ODatabasePool pool = new 
       ODatabasePool(orientDB,dbname,OrientDbConFactory.USER,OrientDbConFactory.PASSWORD, 
       orientDBConfig);
       connPool.put(dbname,pool);
       return pool;
    }
   ...

如果我将记录数限制为 1000,即 'QUERY_REMOTE_RESULTSET_PAGE_SIZE',则查询工作正常。如果记录数超过 1000,我会收到错误消息:数据库 'remote:localhost/testdb' 已关闭

我认为您正在 Try 块外使用 OResultSet,这意味着会话已关闭并且 rs 无法再从数据库中获取更多数据。

 try(ODatabaseSession ses_orient = getConnPool(dbnae).acquire();){
     OResultSet rs = ses_orient.query(query);
     rs.stream()
        .forEach(x -> System.out.println(x.getProperty("propertyName")));
     rs.close();

}

参考文档:

http://orientdb.com/docs/3.0.x/java/Java-Query-API.html