gpt4 book ai didi

java - Firebird : SQL error code = -504 Invalid cursor reference

转载 作者:太空宇宙 更新时间:2023-11-04 06:57:21 27 4
gpt4 key购买 nike

我们使用 firebird、gwt(DATANUCLEUS、持久性对象)来开发 Web 应用程序。

Map<String, String> props = new HashMap<String, String>();
props.put("javax.jdo.PersistenceManagerFactoryClass",
"org.datanucleus.api.jdo.JDOPersistenceManagerFactory");
props.put("javax.jdo.option.ConnectionDriverName",
"org.firebirdsql.jdbc.FBDriver");
props.put("javax.jdo.option.ConnectionURL", "jdbc:firebirdsql://localhost/D:/ XXX fdb");
props.put("javax.jdo.option.ConnectionUserName", "SYSDBA");
props.put("javax.jdo.option.ConnectionPassword", "masterkey");
props.put("javax.jdo.option.NontransactionalRead", "true");
props.put("javax.jdo.option.NontransactionalWrite", "true");
props.put("javax.jdo.option.RetainValues", "true");
props.put("datanucleus.autoCreateSchema", "true");
props.put("datanucleus.query.sql.allowAll", "true");
pmfInstance = JDOHelper.getPersistenceManagerFactory(props);}
private PMF() {
}
public static PersistenceManagerFactory getFactory() {
return pmfInstance;
}
public static PersistenceManager getManager() {
return pmfInstance.getPersistenceManager();
}}}

在 JDO 类中,我们有这个函数,其中 Zone 是一个“JDO 类”:

public static  List<Zone> queryAllZone() {

PersistenceManager pm = PMF.getManager();
Zone result =null;
List<Zone> ListResult = null;//new ArrayList<Zone>();

try {
Query queryJDOQL =pm.newQuery(Zone.class, ***"ID_Zone > value"***);

queryJDOQL.declareParameters("int value");

ListResult = (List<Zone>) queryJDOQL.execute(0);
} finally {
pm.close();
}
return ListResult;
}

我的结果错误:

Starting Jetty on port 0
[WARN] Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.util.List com.exatelys.superviser.client.common.ZoneService.getAllZone()' threw an unexpected exception: javax.jdo.JDOUserException: Exception thrown while loading remaining rows of query
NestedThrowables:
javax.jdo.JDODataStoreException: Failed to read the result set : GDS Exception. 335544569. Dynamic SQL Error
SQL error code = -504
Invalid cursor reference
NestedThrowables:
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544569. Dynamic SQL Error
SQL error code = -504
Invalid cursor reference
at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:389)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:579)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: javax.jdo.JDOUserException: Exception thrown while loading remaining rows of query
NestedThrowables:
javax.jdo.JDODataStoreException: Failed to read the result set : GDS Exception. 335544569. Dynamic SQL Error
SQL error code = -504
Invalid cursor reference
NestedThrowables:
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544569. Dynamic SQL Error
SQL error code = -504
Invalid cursor reference
at org.datanucleus.api.jdo.JDOAdapter.getUserExceptionForException(JDOAdapter.java:1139)
at org.datanucleus.store.rdbms.query.ForwardQueryResult.closingConnection(ForwardQueryResult.java:272)
at org.datanucleus.store.query.AbstractQueryResult.disconnect(AbstractQueryResult.java:107)
at org.datanucleus.store.rdbms.query.AbstractRDBMSQueryResult.disconnect(AbstractRDBMSQueryResult.java:68)
at org.datanucleus.store.rdbms.query.JDOQLQuery$2.managedConnectionPreClose(JDOQLQuery.java:718)
at org.datanucleus.store.rdbms.ConnectionFactoryImpl$ManagedConnectionImpl.close(ConnectionFactoryImpl.java:510)
at org.datanucleus.store.connection.AbstractManagedConnection.release(AbstractManagedConnection.java:77)
at org.datanucleus.store.rdbms.ConnectionFactoryImpl$ManagedConnectionImpl.release(ConnectionFactoryImpl.java:347)
at org.datanucleus.store.rdbms.query.JDOQLQuery.performExecute(JDOQLQuery.java:834)
at org.datanucleus.store.query.Query.executeQuery(Query.java:1786)
at org.datanucleus.store.query.Query.executeWithArray(Query.java:1672)
at org.datanucleus.api.jdo.JDOQuery.execute(JDOQuery.java:243)
at com.exatelys.superviser.server.jdo.Zone.queryAllZone(Zone.java:163)
at com.exatelys.superviser.server.ZoneServiceImpl.getAllZone(ZoneServiceImpl.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
... 22 more
Caused by: javax.jdo.JDODataStoreException: Failed to read the result set : GDS Exception. 335544569. Dynamic SQL Error
SQL error code = -504
Invalid cursor reference
NestedThrowables:
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544569. Dynamic SQL Error
SQL error code = -504
Invalid cursor reference
at org.datanucleus.api.jdo.JDOAdapter.getDataStoreExceptionForException(JDOAdapter.java:1150)
at org.datanucleus.store.rdbms.query.ForwardQueryResult.nextResultSetElement(ForwardQueryResult.java:209)
at org.datanucleus.store.rdbms.query.ForwardQueryResult$QueryResultIterator.next(ForwardQueryResult.java:379)
at org.datanucleus.store.rdbms.query.ForwardQueryResult.processNumberOfResults(ForwardQueryResult.java:137)
at org.datanucleus.store.rdbms.query.ForwardQueryResult.advanceToEndOfResultSet(ForwardQueryResult.java:158)
at org.datanucleus.store.rdbms.query.ForwardQueryResult.closingConnection(ForwardQueryResult.java:260)
... 39 more
Caused by: org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544569. Dynamic SQL Error
SQL error code = -504
Invalid cursor reference
at org.firebirdsql.jdbc.FBStatementFetcher.fetch(FBStatementFetcher.java:206)
at org.firebirdsql.jdbc.FBStatementFetcher.next(FBStatementFetcher.java:137)
at org.firebirdsql.jdbc.AbstractResultSet.next(AbstractResultSet.java:273)
at org.datanucleus.store.rdbms.datasource.dbcp.DelegatingResultSet.next(DelegatingResultSet.java:207)
at org.datanucleus.store.rdbms.datasource.dbcp.DelegatingResultSet.next(DelegatingResultSet.java:207)
at org.datanucleus.store.rdbms.datasource.dbcp.DelegatingResultSet.next(DelegatingResultSet.java:207)
at org.datanucleus.store.rdbms.query.ForwardQueryResult.nextResultSetElement(ForwardQueryResult.java:191)
... 43 more
Caused by: org.firebirdsql.gds.GDSException: Dynamic SQL Error
SQL error code = -504
Invalid cursor reference
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.readStatusVector(AbstractJavaGDSImpl.java:2092)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.receiveResponse(AbstractJavaGDSImpl.java:2042)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.iscDsqlFetch(AbstractJavaGDSImpl.java:1322)
at org.firebirdsql.gds.impl.GDSHelper.fetch(GDSHelper.java:265)
at org.firebirdsql.jdbc.FBStatementFetcher.fetch(FBStatementFetcher.java:201)
... 49 more

当我们在表达式“ID_Zone == value”中使用==比>时,我们得到了很好的结果。但如果我们尝试获取一个列表(不仅仅是对象),我们总是遇到同样的问题。

此外,在每次连接(使用 PMF 类)之后,我们将在 B.D.D 中拥有一个名为deletedxxxxx 的新空​​表。你能帮我吗!!!

最佳答案

问题在于,在 Jaybird 中,TYPE_FORWARD_ONLY 结果集默认是 CLOSE_CURSORS_AT_COMMIT 并按需获取。

当没有使用显式事务时,DataNucleus 在结果集初始化(但不处理)后提交连接,结果 ResultSet 被关闭。

随后,DataNucleus 关闭/释放(托管)连接,这会触发从 ResultSet 进行提取。这会导致错误,因为事务已提交且结果集已关闭。由于 bug在 Jaybird 中,此 ResultSet 关闭不会在本地“处理”,只有当请求到达服务器时,才会触发错误,因为游标句柄不再有效。由于同样的错误,单个项目的获取工作似乎是意外发生的。

我认为 DataNucleus 应该在提交时执行此提取,而不是在连接关闭时执行。看起来它在使用显式事务时确实做到了这一点,但并非没有。

解决方法是:

  1. 使用显式事务
  2. 在连接字符串中指定 defaultHoldable=true 连接属性以使结果集默认为 HOLD_CURSORS_OVER_COMMIT
  3. 将获取大小设置为 eager:queryJDOQL.getFetchPlan().setFetchSize(FetchPlan.FETCH_SIZE_GREEDY);

注意:我使用 Jaybird 2.2.4(最新发布版本)对此进行了测试。

我已将此错误报告为 NUCRDBMS-779 (错误已修复,请参阅票证中的最后评论)

关于java - Firebird : SQL error code = -504 Invalid cursor reference,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22555377/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com