浏览Neo4j-OGM教程here时,一旦连接@Relationship子句,我就会开始收到以下无效输入错误:
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.
DepartmentDataService尝试查找Department时,会发生此错误。我对Neo4j足够陌生,无法确定应该如何显示关系返回的正确格式。
如何找出本教程中我误解的内容?
版本:
Department.java
package com.example;
import java.util.HashSet;
import java.util.Set;
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 Department implements HasId<Long> {
@Id
@GeneratedValue
private Long id;
String name;
@Relationship(type = "CURRICULUM")
Set<Subject> subjects;
public Department() {
super();
}
public Department(final String name, final Subject s) {
this.name = name;
if (s != null) {
subjects = new HashSet<Subject>();
subjects.add(s);
}
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public Set<Subject> getSubjects() {
return subjects;
}
public void setSubjects(final Set<Subject> subjects) {
this.subjects = subjects;
}
@Override
public String toString() {
return "Department [name=" + name + ", subjects=" + subjects + "]";
}
@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;
Department other = (Department) 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;
}
Subject.java
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;
}
}
DepartmentDataService.java
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());
}
}
答案 0 :(得分:1)
该异常来自OGM代码,因此它似乎无法理解模式理解。
There's a bug around this,不确定是否也是造成此问题的原因,但还是一个开始寻找的好地方。
就解决方法而言,您可能希望将模式理解的用法替换为MATCHes和collects()。