java 的 Oracle SODA API - 异常 - 缺少右括号

Oracle SODA API for java - Exception - missing right parenthesis

我正在为 JAVA 使用 Oracle SODA API。我正在使用 oracle 12c 数据库。我正在尝试使用字段上的 desc 排序从集合中获取所有记录。

我写了这样的查询,

{ "$query" : {}, "$orderby" : { "LmCreatedOn" : -1}}

这是java代码,

//  connection code goes above
 final OracleDocument document = db.createDocumentFromString("{ \"$query\" : {}, \"$orderby\" : { \"LmCreatedOn\" : -1}}");

            final OracleCursor cursor = db.openCollection(SC_LMS_ADMIN_COURSE).find().filter(document).getCursor();

            List<JsonNode> listDto = new ArrayList<JsonNode>();

            while(cursor.hasNext()) {
                final OracleDocument doc = cursor.next();
                listDto.add(JacksonUtils.getObjectMapper().readTree(doc.getContentAsString()));
             }

但是我遇到了一个例外,

oracle.soda.rdbms.impl.SODAUtilsOracleSQLException at oracle.soda.rdbms.impl.SODAUtils.makeExceptionWithSQLText(SODAUtils.java:112) at oracle.soda.rdbms.impl.SODAUtils.makeExceptionWithSQLText(SODAUtils.java:75) at oracle.soda.rdbms.impl.OracleOperationBuilderImpl.getResultSet(OracleOperationBuilderImpl.java:684) at oracle.soda.rdbms.impl.OracleOperationBuilderImpl.getResultSet(OracleOperationBuilderImpl.java:655) at oracle.soda.rdbms.impl.OracleOperationBuilderImpl.getCursor(OracleOperationBuilderImpl.java:702) at com.cisco.salesconnect.lms.SCLmsServiceHandler.getLMSCourses(SCLmsServiceHandler.java:198) at com.cisco.salesconnect.lms.SCLmsService.getLMSCourses(SCLmsService.java:98) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.invoke(ResourceMethodInvocationHandlerFactory.java:81) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.run(AbstractJavaResourceMethodDispatcher.java:144) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161) at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:205) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99) at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389) at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347) at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102) at org.glassfish.jersey.server.ServerRuntime.run(ServerRuntime.java:326) at org.glassfish.jersey.internal.Errors.call(Errors.java:271) at org.glassfish.jersey.internal.Errors.call(Errors.java:267) at org.glassfish.jersey.internal.Errors.process(Errors.java:315) at org.glassfish.jersey.internal.Errors.process(Errors.java:297) at org.glassfish.jersey.internal.Errors.process(Errors.java:267) at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305) at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473) at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: java.sql.SQLSyntaxErrorException: ORA-00907: missing right parenthesis at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399) at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1059) at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:522) at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:257) at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:587) at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:225) at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:53) at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:774) at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:925) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1111) at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:4798) at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:4845) at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1501) at oracle.soda.rdbms.impl.OracleOperationBuilderImpl.getResultSet(OracleOperationBuilderImpl.java:665) ... 52 more

我通过以下方式解决了这个问题,

根据oracle doc

If you use Oracle Database Release 12c (12.1.0.2) then you must specify either $scalarRequired or $lax; otherwise a syntax error is raised.

因为我使用的是 Oracle 数据库版本 12c (12.1.0.2)。我在没有 $scalarRequired 的情况下使用查询 json。这就是它抛出语法错误的原因。

更新后的查询是,

{ \"$query\": {}, \"$orderby\" : { \"$fields\" : [{ \"path\" : \"LmCreatedOn\", \"datatype\" : \"varchar2\", \"order\" : \"desc\"}], \"$scalarRequired\" : true }}

这里我也根据oracle doc更新了查询格式。我提供了一些额外的 fields 和额外的细节。此功能出现在最新 soda jar 1.1.0