Java Spring框架Neo4jRepository函数findById导致密码错误
背景 我的spring data neo4j应用程序出现密码错误 这很奇怪,因为我使用neo ogm来管理我所有的cyper语句,我自己也没有写过任何cypher 以下是我的错误: CLI输出中的密码错误Java Spring框架Neo4jRepository函数findById导致密码错误,java,spring,spring-data-neo4j,neo4j-ogm,spring-data-neo4j-5,Java,Spring,Spring Data Neo4j,Neo4j Ogm,Spring Data Neo4j 5,背景 我的spring data neo4j应用程序出现密码错误 这很奇怪,因为我使用neo ogm来管理我所有的cyper语句,我自己也没有写过任何cypher 以下是我的错误: CLI输出中的密码错误 Error executing Cypher "Neo.ClientError.Statement.SyntaxError"; Code: Neo.ClientError.Statement.SyntaxError; Description: Invalid input '|': expect
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 ']...
在我的代码中查找错误来源的位置时出错(GenericService)
通用服务第39行
...myproject.service.GenericService.find(GenericService.java:39) ~[classes/:na]...
Optional object=getRepository().findById(id,depth)代码>
我被困的地方
findById
在springframework.data.neo4j.repository.Neo4jRepository.java中声明为可选findById(ID,int-depth)代码>
自从切换到Spring数据neo4j 5.0.0以来,我最近开始使用neo4jrepository而不是GraphRespository
因此,我想我已经在代码中找到了问题所在,但这不是我的代码,而是库,但我不敢相信最近发布的neo4j ogm在findById
函数中有一个bug
问题
我如何克服这个密码错误?这个问题可能来自哪里
更新1
我使用的是neo4j ogm版本3.0.0、spring boot 2.0.0.M3、neo4j is 3.2.3和spring-data-neo4j 5.0.0.0.0
更新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;
}
public找不到(长id){
可选对象=getRepository().findById(id,DEPTH\u实体);
if(object.isPresent())
返回object.get();
返回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);
}
@NoRepositoryBean
公共接口Neo4jRepository扩展了分页和排序存储库{
S保存(S,整数深度);
Iterable保存(Iterable实体,int深度);
可选的findById(ID,int-depth);
Iterable findAll();
Iterable findAll(整数深度);
Iterable findAll(排序);
Iterable findAll(排序,整数深度);
Iterable findAllById(Iterable id);
Iterable findAllById(Iterable ID,int depth);
Iterable findAllById(Iterable id,Sort-Sort);
Iterable findAllById(Iterable id、Sort Sort、int depth);
/**
*返回满足{@code Pageable}对象中提供的分页限制的{@link Page}实体。
*{@link Page#getTotalPage()}返回总页数的估计值,不应依赖于其准确性。
*
*@param可分页
*@返回一页实体
*/
页面findAll(可分页可分页);
/**
*返回满足{@code Pageable}对象中提供的分页限制的{@link Page}实体。
*{@link Page#getTotalPage()}返回总页数的估计值,不应依赖于其准确性。
*
*@param可分页
*@param深度
*@返回一页实体
*/
pagefindall(可分页、可分页、整数深度);
}
看起来您对Java及其泛型类型不是很熟悉
让我们一步一步来:
例如,您需要定义一个实体
@NodeEntity
public class User {
@Id @GeneratedValue
private Long id;
...
然后定义一个从SDN扩展Neo4jRepository的存储库
public interface UserRepository extends Neo4jRepository<User, Long> {
}
成为存储库中的此专用版本
Optional<User> findById(Long id, int depth);
可选findById(长id,int-depth);
您从不直接使用Neo4jRepository
,只使用您定义的子接口
有关更多详细信息,请查看。还要考虑一下java泛型类型。
更新
...myproject.service.GenericService.find(GenericService.java:39) ~[classes/:na]...
除了SDN的使用不正确之外,我认为错误的原因是您使用的Neo4j版本<3.1
我非常怀疑您使用的是您评论中指定的3.2.3。请仔细检查。你的Neo4j版本是什么?Neo4j是版本3.2.3@NMervailiec你可以发布你的存储库和实体的代码吗?@NMervailie springframework.data.Neo4j.repository.Neo4jRepository.java是我的存储库,而DEPTH_实体只是公共静态最终int-DEPTH_-entity=1代码>我在更新3中添加了repo文件代码在看到您的更新后,我重新检查了我的neo4j,发现我有一个在localhost和3.2.3上运行的neo4j 3.0.11。同时运行(我甚至不知道这是可能的)。这可能是我问题的核心。如果我在删除旧的neo4j后运行代码,我将接受您的回答。
Optional<User> findById(Long id, int depth);