我正在嘗試爲neo4j 3.0.0編寫一個插件。爲了測試水,我寫了這個非常簡單的方法來公開即將離任的程度。當我嘗試打電話給我的插件時,neo4j說我需要在交易中包裝我的電話
public class Utils extends ServerPlugin {
@PluginTarget(value = Node.class)
public int outgoingDegree(@Source Node node) {
return node.getDegree(Direction.OUTGOING);
}
}
註冊插件完美地工作:
curl -v http://localhost:7474/db/data/ext/
{
"Utils" : "http://localhost:7474/db/data/ext/Utils"
}
我的小方法有:
curl -v http://localhost:7474/db/data/ext/Utils
{
"node" : {
"outgoingDegree" : {
"extends" : "node",
"name" : "outgoingDegree",
"description" : "",
"parameters" : [ ]
}
}
}
令人驚歎。現在,當我嘗試調用此方法,一切都順心:
url -XPOST -v http://localhost:7474/db/data/ext/Utils/node/20/outgoingDegree -H "Accept: application/json" -H "Content-type: application/json" -d "{ }"
{
"message" : "The requested operation cannot be performed, because it has to be performed in a transaction. Ensure you are wrapping your operation in the appropriate transaction boilerplate and try again.",
"exception" : "BridgeNotInTransactionException",
"fullname" : "org.neo4j.kernel.impl.core.ThreadToStatementContextBridge$BridgeNotInTransactionException",
"stackTrace" : [ "org.neo4j.kernel.impl.core.ThreadToStatementContextBridge.assertInUnterminatedTransaction(ThreadToStatementContextBridge.java:72)", "org.neo4j.kernel.impl.core.ThreadToStatementContextBridge.getTopLevelTransactionBoundToThisThread(ThreadToStatementContextBridge.java:105)", "org.neo4j.kernel.impl.core.ThreadToStatementContextBridge.getKernelTransactionBoundToThisThread(ThreadToStatementContextBridge.java:113)", "org.neo4j.kernel.impl.core.ThreadToStatementContextBridge.get(ThreadToStatementContextBridge.java:65)", "org.neo4j.kernel.impl.factory.ClassicCoreSPI.currentStatement(ClassicCoreSPI.java:205)", "org.neo4j.kernel.impl.factory.GraphDatabaseFacade$$Lambda$76/46581122.get(Unknown Source)", "org.neo4j.kernel.impl.coreapi.StandardNodeActions.statement(StandardNodeActions.java:56)", "org.neo4j.kernel.impl.core.NodeProxy.getDegree(NodeProxy.java:702)", "com.github.denizco.datascience.neo4jplugin.Utils.outgoingDegree(Utils.java:12)", "java.lang.reflect.Method.invoke(Method.java:483)", "org.neo4j.server.plugins.PluginMethod.invoke(PluginMethod.java:61)", "org.neo4j.server.plugins.PluginManager.invoke(PluginManager.java:158)", "org.neo4j.server.rest.web.ExtensionService.invokeNodeExtension(ExtensionService.java:325)", "org.neo4j.server.rest.web.ExtensionService.invokeNodeExtension(ExtensionService.java:184)", "java.lang.reflect.Method.invoke(Method.java:483)", "org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:144)", "org.neo4j.server.rest.dbms.AuthorizationFilter.doFilter(AuthorizationFilter.java:121)", "org.neo4j.server.rest.web.CollectUserAgentFilter.doFilter(CollectUserAgentFilter.java:69)", "java.lang.Thread.run(Thread.java:745)" ],
"errors" : [ {
"code" : "Neo.ClientError.Request.TransactionRequired",
"message" : "The requested operation cannot be performed, because it has to be performed in a transaction. Ensure you are wrapping your operation in the appropriate transaction boilerplate and try again."
} ]
}
這是怎麼回事?爲什麼我需要在交易中包裝我的電話,我該怎麼做?有沒有解決的辦法?
不夠公平,我會使用程序。 – Tillerino