Neo4j返回事务错误

Neo4j返回事务错误,neo4j,amazon,Neo4j,Amazon,我正在亚马逊上安装neo4j 我创建了一个客户端,它使用远程执行cypher语句的neo4jdbc 如果我在本地运行neo4jdbc客户机,在amazon上远程运行neo4j实例,那么一切都会正常工作 但是,当我将我的Neo4jJDBC客户端应用程序上载到 amazon并执行语句,我得到这个异常: 2015-10-06 10:59:59,609 ERROR [com.mycompany.wm.common.repo.Neo4jRepo] - <Error returning userId=

我正在亚马逊上安装neo4j

我创建了一个客户端,它使用远程执行cypher语句的neo4jdbc

如果我在本地运行neo4jdbc客户机在amazon上远程运行neo4j实例,那么一切都会正常工作

但是,当我将我的Neo4jJDBC客户端应用程序上载到
amazon
并执行语句,我得到这个异常:

2015-10-06 10:59:59,609 ERROR [com.mycompany.wm.common.repo.Neo4jRepo] - <Error returning userId=33>
java.sql.SQLException: Error executing statement
    at org.neo4j.jdbc.internal.rest.TransactionalQueryExecutor.executeQuery(TransactionalQueryExecutor.java:224)
    at org.neo4j.jdbc.internal.Neo4jConnection.executeQuery(Neo4jConnection.java:370)
    at org.neo4j.jdbc.internal.Neo4jPreparedStatement.executeQuery(Neo4jPreparedStatement.java:48)
    at com.mycompany.wm.common.repo.Neo4jRepo.getfollowUsersByProximitySensors(Neo4jRepo.java:159)
    at com.mycompany.wm.core.dao.LocationServiceDaoImpl.getfollowUsersByProximitySensors(LocationServiceDaoImpl.java:79)
    at com.mycompany.wm.core.service.LocationServiceImpl.getfollowUsers(LocationServiceImpl.java:38)
    at com.mycompany.world_map_service.web.http.VertxHttpServerVerticle.getUsersLocation(VertxHttpServerVerticle.java:69)
    at com.mycompany.world_map_service.web.http.VertxHttpServerVerticle$$Lambda$30/984195839.handle(Unknown Source)
    at io.vertx.ext.web.impl.RouteImpl.handleContext(RouteImpl.java:218)
    at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:67)
    at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:96)
    at io.vertx.ext.web.impl.RouterImpl.accept(RouterImpl.java:61)
    at com.mycompany.world_map_service.web.http.VertxHttpServerVerticle$$Lambda$32/1901044330.handle(Unknown Source)
    at io.vertx.core.http.impl.ServerConnection.handleRequest(ServerConnection.java:276)
    at io.vertx.core.http.impl.ServerConnection.processMessage(ServerConnection.java:391)
    at io.vertx.core.http.impl.ServerConnection.handleMessage(ServerConnection.java:137)
    at io.vertx.core.http.impl.HttpServerImpl$ServerHandler.lambda$createConnAndHandle$24(HttpServerImpl.java:539)
    at io.vertx.core.http.impl.HttpServerImpl$ServerHandler$$Lambda$55/521685526.run(Unknown Source)
    at io.vertx.core.impl.ContextImpl.lambda$wrapTask$15(ContextImpl.java:312)
    at io.vertx.core.impl.ContextImpl$$Lambda$11/1686783496.run(Unknown Source)
    at io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:217)
    at io.vertx.core.http.impl.HttpServerImpl$ServerHandler.createConnAndHandle(HttpServerImpl.java:537)
    at io.vertx.core.http.impl.HttpServerImpl$ServerHandler.doMessageReceived(HttpServerImpl.java:474)
    at io.vertx.core.http.impl.HttpServerImpl$ServerHandler.doMessageReceived(HttpServerImpl.java:425)
    at io.vertx.core.http.impl.VertxHttpHandler.channelRead(VertxHttpHandler.java:85)
    at io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:124)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:244)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:110)
    at java.lang.Thread.run(Thread.java:745)
Caused by: Error executing statement (404) - {"results":[],"errors":[{"code":"Neo.ClientError.Transaction.UnknownId","message":"Unrecognized transaction id. Transaction may have timed out and been rolled back."}]}
    at org.restlet.resource.ClientResource.doError(ClientResource.java:612)
    at org.neo4j.jdbc.internal.rest.Resources$TransactionClientResource.doError(Resources.java:283)
    at org.restlet.resource.ClientResource.handleInbound(ClientResource.java:1202)
    at org.restlet.resource.ClientResource.handle(ClientResource.java:1069)
    at org.restlet.resource.ClientResource.handle(ClientResource.java:1044)
    at org.restlet.resource.ClientResource.post(ClientResource.java:1453)
    at org.neo4j.jdbc.internal.rest.TransactionalQueryExecutor.post(TransactionalQueryExecutor.java:98)
    at org.neo4j.jdbc.internal.rest.TransactionalQueryExecutor.begin(TransactionalQueryExecutor.java:76)
    at org.neo4j.jdbc.internal.rest.TransactionalQueryExecutor.executeQuery(TransactionalQueryExecutor.java:214)
    ... 38 more

运行此方法:

 public Set<UserDistanceDTO> getfollowUsers(String userIdInput, boolean includeHopes, follow_RELATIONSHIP_TYPE relationship_type) {
        String followExpression = "follow";
        if (includeHopes) {
            followExpression = "follow*1..3";
        }

        String relationshipTye;
        if (relationship_type.equals(follow_RELATIONSHIP_TYPE.OUTGOING)) {
            relationshipTye = "->";

        } else if (relationship_type.equals(follow_RELATIONSHIP_TYPE.INCOMING)) {
            relationshipTye = "<-";

        } else {
            relationshipTye = "-";
        }
        Set<UserDistanceDTO> userDistanceDTOs = null;
        try {
            userDistanceDTOs = new HashSet<>();

            String getUsersStatement =
                    "MATCH (user:" + LABEL_NAME + " {userId:{1}})-[r:" + followExpression + "]" + relationshipTye + "f " +
                            "WHERE f <> user " +
                            "RETURN DISTINCT (f.userId) as userId";
            final PreparedStatement ps = conn.prepareStatement(getUsersStatement);
            ps.setString(1, userIdInput);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                userDistanceDTOs.add(new UserDistanceDTO((String) rs.getObject("userId"), 0));
            }

        } catch (SQLException e) {
            e.printStackTrace();
            logger.error("Error returning userId=" + userIdInput, e);
        }
        return userDistanceDTOs;
    }

}
public Set getfollowUsers(字符串userIdInput,布尔includeOpes,follow\u关系类型关系类型){
字符串followExpression=“follow”;
如果(包括操作){
followExpression=“follow*1..3”;
}
字符串关系;
if(关系类型等于(跟随关系类型传出)){
关系类型=“->”;
}else if(关系类型等于(跟随关系类型传入)){

relationshipTye=“您应该验证您的代码

正如我看到的,您正在创建语句:

final PreparedStatement ps = conn.prepareStatement(getUsersStatement);
但您永远不会关闭它们。看起来这是有状态的,若您不关闭语句,那个么以前的事务元数据将泄漏到新的事务中

尝试在语句中使用
Try with resource
语法。示例:

try (final PreparedStatement ps = conn.prepareStatement(getUsersStatement)) {
    ps.setString(1, userIdInput);
    ResultSet rs = ps.executeQuery();
    while (rs.next()) {
        userDistanceDTOs.add(new UserDistanceDTO((String) rs.getObject("userId"), 0));
    } 
}
注意:neo4j jdbc正在使用。这一点应该牢记在心。因为当您创建新语句时,它会在服务器上创建新事务并检索其id。执行查询时,它会使用指定的事务id调用API方法。

数据库中还有事务超时。如果事务未使用
n
秒,则事务将关闭。

请共享代码示例-您如何使用neo4j jdbc。这将有助于发现问题。完成。请检查代码我看不到您的代码示例的差异。它看起来是一样的eh?
尝试(最终编制报表ps=conn.prepareStatement(getUsersStatement)){
我正在使用
try-with-resource
语法和prepared语句。这样,当到达
try
块的末尾时,语句将被关闭。在使用try-with-resources进行所有操作后,我仍然会收到相同的错误,Mybe我还有其他东西要关闭吗?我正在使用相同的连接进行其他并发查询,您应该这样做不要同时使用连接。为每个线程创建新连接。可能您应该创建连接池。我更新了关于事务端点的说明。您的意思是我应该执行conn=DriverManager.getConnection(connectionString,new Properties());对于每个事务?因为现在我只初始化conn一次,并在所有语句中使用它
try (final PreparedStatement ps = conn.prepareStatement(getUsersStatement)) {
    ps.setString(1, userIdInput);
    ResultSet rs = ps.executeQuery();
    while (rs.next()) {
        userDistanceDTOs.add(new UserDistanceDTO((String) rs.getObject("userId"), 0));
    } 
}