配置关系时如何调试无效的输入密码查询?(Neo4j OGM)
在阅读Neo4j OGM教程时,只要插入@Relationship子句,就会出现以下无效输入错误:配置关系时如何调试无效的输入密码查询?(Neo4j OGM),neo4j,neo4j-ogm,Neo4j,Neo4j Ogm,在阅读Neo4j OGM教程时,只要插入@Relationship子句,就会出现以下无效输入错误: WARN [main] (Neo4jSession.java:550) - Error executing query : Neo.ClientError.Statement.SyntaxError - Invalid input '|' : expected whitespace, comment, a relationship pattern, '.', node labels, '[',
WARN [main] (Neo4jSession.java:550) - Error executing query : Neo.ClientError.Statement.SyntaxError - Invalid input '|'
: expected whitespace, comment, a relationship pattern, '.', node labels, '[', "=~", IN, STARTS, ENDS, CONTAINS, IS, '^'
, '*', '/', '%', '+', '-', '=', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR, ',' or ']' (line 1, column 105 (offset:
104))
"MATCH (n:`Subject`) WHERE ID(n) = { id } WITH n RETURN n,[ [ (n)<-[r_c1:`CURRICULUM`]-(d1:`Department`) | [ r_c1, d1 ] ] ]"
^. Rolling back transaction.
WARN[main](Neo4jSession.java:550)-执行查询时出错:Neo.ClientError.Statement.SyntaxError-输入无效“|”
:应为空白、注释、关系模式“.”、节点标签“[”、“=~”、IN、STARTS、ENDS、CONTAINS、IS“^”
“*”、“/”、“%”、“+”、“-”、“=”、“!=”、“、”、“=”、和、异或、“、”或“]”(第1行第105列(偏移量:
104))
匹配(n:`Subject`),其中ID(n)={ID},n返回n,[[(n)异常来自OGM代码,因此看起来它不理解模式理解
,不确定这是否也是这个问题的原因,但这是一个开始寻找的好地方
就解决方法而言,您可能希望用MATCHes and collects()替换模式理解的用法。关于查询和错误,查询使用3.3.6编译和执行(不过,在模式理解中有一个额外的[]嵌套是不必要的),因此查询本身没有问题。我使用的是3.3.6,无法让它编译/运行…我不明白什么?在浏览器中应该可以正常运行。在下面的回答中,我指出这是OGM问题。
package com.example;
import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship;
@NodeEntity
public class Subject implements HasId<Long>{
@Id
@GeneratedValue
private Long id;
String name;
@Relationship(type="CURRICULUM", direction = Relationship.INCOMING)
Department department;
public Subject(final String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public Department getDepartment() {
return department;
}
public void setDepartment(final Department department) {
this.department = department;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Subject other = (Subject) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
@Override
public Long getId() {
return id;
}
}
package com.example;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.neo4j.ogm.session.Session;
public class DepartmentDataService {
private Class<Department> getEntityType() {
return Department.class;
}
private static final int DEPTH_LIST = 0;
private static final int DEPTH_ENTITY = 1;
protected Session session = Neo4jSessionFactory.getInstance().getNeo4jSession();
public List<Department> findAll() {
final Collection<Department> results = session.loadAll(getEntityType(), DEPTH_LIST);
return new ArrayList<Department>(results);
}
public Department find(final long id) {
return session.load(getEntityType(), id, DEPTH_ENTITY);
}
public void delete(final long id) {
session.delete(session.load(getEntityType(), id));
}
public Department createOrUpdate(final Department entity) {
session.save(entity, DEPTH_ENTITY);
return find(entity.getId());
}
}