gpt4 book ai didi

java - Spring 框架 Neo4jRepository 函数 findById 导致密码错误

转载 作者:行者123 更新时间:2023-11-30 02:21:39 26 4
gpt4 key购买 nike

背景

我的 spring data neo4j 应用程序给出了密码错误。

这很奇怪,因为我使用 neo ogm 来管理我所有的 cyper 语句,我自己没有编写任何 cypher。

这是我的错误:

CLI 输出中的密码错误

Error executing Cypher "Neo.ClientError.Statement.SyntaxError"; Code: Neo.ClientError.Statement.SyntaxError; Description: Invalid input '|': expected whitespace, comment, a relationship pattern, '.', node labels, '[', "=~", IN, STARTS, ENDS, CONTAINS, IS, '^', '*', '/', '%', '+', '-', '=', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR, ',' or ']...

密码错误后 CLI 输出中出现 OGM 错误

...nested exception is org.neo4j.ogm.exception.CypherException: Error executing Cypher \"Neo.ClientError.Statement.SyntaxError\"; Code: Neo.ClientError.Statement.SyntaxError; Description: Invalid input '|': expected whitespace, comment, a relationship pattern, '...

在代码中定位错误发生的位置时出错 (GenericService)

...myproject.service.GenericService.find(GenericService.java:39) ~[classes/:na]...

GenericService第39行

Optional<T> object = getRepository().findById(id, depth);

我陷入困境

findById在 springframework.data.neo4j.repository.Neo4jRepository.java 中声明为 Optional<T> findById(ID id, int depth);

自从我切换到 Spring data neo4j 5.0.0 以来,我最近开始使用 neo4jrepository 而不是 graphrepository。

所以,我想我已经在代码中找到了问题,但它不是我的代码,而是库,但我不能相信最新的 neo4j ogm 发布时存在 findById 中的错误功能。

问题

如何解决此密码错误?这个问题可能源自哪里?

更新1

我使用的是neo4j-ogm-version 3.0.0,spring-boot 2.0.0.M3,Neo4J是3.2.3,spring-data-neo4j 5.0.0.RELEASE,

更新2

难道我的id被实例化为Long而 Neo4jRepository.java 已实例化为 ID

GenericService.java 中的

更多上下文

public T find(Long id) {
Optional<T> object = getRepository().findById(id, DEPTH_ENTITY);
if(object.isPresent())
return object.get();
return null;
}

更新3

springframework.data.neo4j.repository.Neo4jRepository.java包含

@NoRepositoryBean
public interface Neo4jRepository<T, ID extends Serializable> extends PagingAndSortingRepository<T, ID> {

<S extends T> S save(S s, int depth);

<S extends T> Iterable<S> save(Iterable<S> entities, int depth);

Optional<T> findById(ID id, int depth);

Iterable<T> findAll();

Iterable<T> findAll(int depth);

Iterable<T> findAll(Sort sort);

Iterable<T> findAll(Sort sort, int depth);

Iterable<T> findAllById(Iterable<ID> ids);

Iterable<T> findAllById(Iterable<ID> ids, int depth);

Iterable<T> findAllById(Iterable<ID> ids, Sort sort);

Iterable<T> findAllById(Iterable<ID> ids, Sort sort, int depth);

/**
* Returns a {@link Page} of entities meeting the paging restriction provided in the {@code Pageable} object.
* {@link Page#getTotalPages()} returns an estimation of the total number of pages and should not be relied upon for accuracy.
*
* @param pageable
* @return a page of entities
*/
Page<T> findAll(Pageable pageable);

/**
* Returns a {@link Page} of entities meeting the paging restriction provided in the {@code Pageable} object.
* {@link Page#getTotalPages()} returns an estimation of the total number of pages and should not be relied upon for accuracy.
*
* @param pageable
* @param depth
* @return a page of entities
*/
Page<T> findAll(Pageable pageable, int depth);
}

最佳答案

看来您对 Java 及其泛型类型不太熟悉。

让我们一步一步来:

  1. 例如,您需要定义一个实体

    @NodeEntity
    public class User {
    @Id @GeneratedValue
    private Long id;
    ...
  2. 然后定义一个从 SDN 扩展 Neo4jRepository 的存储库

    public interface UserRepository extends Neo4jRepository<User, Long> {
    }

通过这种方式,您可以通过指示您希望存储库来管理其身份由 Long 定义的 User 来专门化 Neo4jRepositoryNeo4jRepository 中定义的方法:

Optional<T> findById(ID id, int depth);

成为您存储库中的专用版本

Optional<User> findById(Long id, int depth);

您永远不会直接使用Neo4jRepository,而只能使用您定义的子接口(interface)。

欲了解更多详情,请查看Spring Data commons reference 。还可以考虑看看 java 泛型类型。

更新

除了SDN的使用不正确之外,我认为错误的原因是你使用了Neo4j版本<3.1

我非常怀疑您正在使用评论中指定的 3.2.3。请仔细检查。

关于java - Spring 框架 Neo4jRepository 函数 findById 导致密码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46652797/

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