尝试使用自定义过程提交提交时遇到问题。我正在从外部数据源中选择数据,然后将其转换为图形数据库。我试图使外部数据源中的每一行都是它自己的事务,但是如果任何行失败,则所有事务都会失败。请让我知道我哪里出错了。这是我的代码段:
@Context
public GraphDatabaseService db;
@SuppressWarnings("unchecked")
@Description("CALL myProc")
@Procedure(name = "myProc", mode = Mode.WRITE)
public void myProc() {
// Get the last time the procedure succeeded from the System node
try {
boolean processAgain = true;
int startRow = 1, endRow = 10000, batchSize = 10000;
int total = 0, succeeded = 0, failed = 0;
while (processAgain) {
result = db.execute(new StringBuilder("CALL apoc.load.jdbc(\"dbAlias\", \"SQL GOES HERE\")").toString());
while (result.hasNext()) {
total++;
Map<String, Object> row = result.next();
for (String key : result.columns()) {
Map<String, Object> currentRow = ((Map<String, Object>) row.get(key));
Transaction trans = db.beginTx();
log.info("Beginning transaction");
try {
// Do stuff here (i.e. db.execute...)
trans.success();
succeeded++;
} catch (Exception e) {
failed++;
log.error("Error message", e);
} finally {
trans.close();
}
}
} // End results while loop
if (total != 0) {
log.info(new StringBuilder("Processed ").append(total - startRow + 1).append(" rows").toString());
}
processAgain = total != 0 && total % endRow == 0;
startRow += batchSize;
endRow += batchSize;
} // End processAgain while loop
} catch (Exception e) {
log.error("Error message", e);
}
}
更新:这是控制台输出
ERROR (-v for expanded information):
TransactionFailureException: Transaction was marked as successful, but unable to commit transaction so rolled back.
org.neo4j.graphdb.TransactionFailureException: Transaction was marked as successful, but unable to commit transaction so rolled back.
at org.neo4j.kernel.impl.coreapi.TopLevelTransaction.close(TopLevelTransaction.java:100)
at org.neo4j.shell.kernel.apps.TransactionProvidingApp.execute(TransactionProvidingApp.java:250)
at org.neo4j.shell.kernel.apps.cypher.Start.execute(Start.java:82)
at org.neo4j.shell.impl.AbstractAppServer.interpretLine(AbstractAppServer.java:126)
at org.neo4j.shell.kernel.GraphDatabaseShellServer.interpretLine(GraphDatabaseShellServer.java:105)
at org.neo4j.shell.impl.RemotelyAvailableServer.interpretLine(RemotelyAvailableServer.java:61)
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 sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.neo4j.internal.kernel.api.exceptions.TransactionFailureException: Transaction rolled back even if marked as successful
at org.neo4j.kernel.impl.api.KernelTransactionImplementation.failOnNonExplicitRollbackIfNeeded(KernelTransactionImplementation.java:599)
at org.neo4j.kernel.impl.api.KernelTransactionImplementation.closeTransaction(KernelTransactionImplementation.java:541)
at org.neo4j.internal.kernel.api.Transaction.close(Transaction.java:189)
at org.neo4j.kernel.impl.coreapi.TopLevelTransaction.close(TopLevelTransaction.java:78)
... 22 more
有人可以告诉我我做错了什么吗?谢谢。