在Neo4j中查询不存在的标签时,MyBatis映射器永远不会返回

时间:2018-05-06 19:27:10

标签: neo4j mybatis spring-mybatis

我有一个非常简单的Spring Boot 2应用程序和MyBatis Spring Boot启动程序:

@Slf4j
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Autowired
    UserMapper userMapper;

    @Bean
    public CommandLineRunner commandLineRunner() {
        return (args -> {
            final List<User> users = userMapper.getUsers();
            log.info("users: {}", users);
        });
    }

    @Bean
    @ConfigurationProperties(prefix="app.datasource")
    public DataSource dataSource() {
        return DataSourceBuilder.create().type(HikariDataSource.class).build();
    }

}

当我在Neo4j数据库中拥有一个用户时,它运行良好。但是如果它们不是,那么对getUsers的调用永远不会返回,没有超时,没有任何事情发生,就像应用程序永远停滞不前一样。 有什么想法会发生这种情况吗?

编辑: 显然它是在MyBatis的DefaultResultSetHandler类中循环。

  private ResultSetWrapper getFirstResultSet(Statement stmt) throws SQLException {
    ResultSet rs = stmt.getResultSet();
    while (rs == null) {
      // move forward to get the first resultset in case the driver
      // doesn't return the resultset as the first result (HSQLDB 2.1)
      if (stmt.getMoreResults()) {
        rs = stmt.getResultSet();
      } else {
        if (stmt.getUpdateCount() == -1) {
          // no more results. Must be no resultset
          break;
        }
      }
    }
    return rs != null ? new ResultSetWrapper(rs, configuration) : null;
  }

ResultSet为null,因为没有User。 但是stmt.getMoreResults()从Neo4jInvocationHandler中返回true:

@Override public boolean getMoreResults() throws SQLException {
        this.checkClosed();
        return !(this.currentResultSet == null && this.currentUpdateCount == -1);
    }

currentUpdateCount为0,因为在BoltNeo4jPreparedStatement中:

@Override public boolean execute() throws SQLException {
        StatementResult result = executeInternal();

        boolean hasResultSet = hasResultSet(result);
        if (hasResultSet) {
            this.currentResultSet = BoltNeo4jResultSet.newInstance(this.hasDebug(), this, result, this.resultSetParams);
            this.currentUpdateCount = -1;
        } else {
            this.currentResultSet = null;
            try {
                SummaryCounters stats = result.consume().counters();
                this.currentUpdateCount = stats.nodesCreated() + stats.nodesDeleted() + stats.relationshipsCreated() + stats.relationshipsDeleted();
            } catch (Exception e) {
                throw new SQLException(e);
            }
        }
        return hasResultSet;
    }

我认为需要更新getMoreResults实现。
也许在MyBatis PreparedStatementHandler中,他们应该检查execute()方法的返回值。

1 个答案:

答案 0 :(得分:0)

neo4j-jdbc 3.3.1已解决此问题。参见https://github.com/neo4j-contrib/neo4j-jdbc/issues/137