В Java Eclipse я создал свой код на основе учебника по neo4j OGM https://neo4j.com/docs/ogm-manual/current/tutorial/, но когда я использую метод loadAll (), он загружает все узлы и отношения, которые имеют одну и ту же метку, но это делает не загружать узлы разными метками. Это два узла, которые я создал. Это простой пример того, что я пытаюсь сделать, но не работаю.
@NodeEntity
public class Child {
@Id@GeneratedValue
private Long id;
private String name;
@Relationship(type = "PARENT_OF", direction = Relationship.INCOMING)
Parent parent;
public String getName() {
return name;
}
public Parent getParent() {
return parent;
}
}
@NodeEntity
public class Parent {
@Id@GeneratedValue
private Long id;
private String name;
@Relationship(type = "PARENT_OF")
Set<Child> children;
public String getName() {
return name;
}
public Set<Child> getChildren() {
return children;
}
}
И вот как я пытаюсь получить доступ к данным.
import org.neo4j.ogm.config.Configuration;
import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;
public class Main {
private SessionFactory sessionFactory=null;
private Session session=null;
private Configuration configuration=null;
private final String uri = "bolt://localhost:7687";
private final String user = "neo4j";
private final String password = "admin";
private void connect(String entityName) {
System.out.println("Connecting to Neo4j ("+uri+")");
if(configuration==null) {
configuration = new Configuration.Builder()
.uri(uri)
.credentials(user, password)
.build();
}
sessionFactory = new SessionFactory(configuration, entityName);
session = sessionFactory.openSession();
}
private void disconnect() {
System.out.println("Closing the connection.");
sessionFactory.close();
}
public Collection<Parent> getParents() {
connect(Parent.class.getName());
Collection<Parent> projects = session.loadAll(Parent.class);
disconnect();
return projects;
}
public static void main(String[] args) {
Main m = new Main();
Collection<Parent> a = m.getParents();
for (Iterator iterator = a.iterator(); iterator.hasNext();) {
Parent parent = (Parent) iterator.next();
System.out.println(parent.getName());
System.out.println(parent.getChildren());
}
}
}
Я уже попробовал то, что было по этой ссылке https://github.com/neo4j/neo4j-ogm/issues/32. Если кто-нибудь может сказать мне, что я делаю неправильно, я бы оценил это.
Я neo4j-ogm 3.1.1 и neo4j-ogm-bolt-driver3.0.2