DB로 Java SpringBoot 및 Neo4j를 사용하고 있습니다.Java SpringBoot에서 일반 시작 노드를 가질 수 있고 나중에 유형을 할당 할 수 있습니까?
일반적인 StartNode로 RelationshipEntity를 선언하고 싶습니다. 그런 다음 객체를 만들 때 관계를 연결하려는 NodeEntity를 전달합니다.
각 시작/끝 노드 유형에 대해 복제하지 않도록 관계 클래스를 어떻게 수행 할 수 있습니까?
예 :
인격 및 회사 노드 클래스의 다음@RelationshipEntity(type = "RESIDES_AT")
public class ResidesAt {
@StartNode
private Object startNode; //Can be Company or Person
...
@EndNode
private Address address;
}
내가 가진 :
@NodeEntity (label="Company")
public class Company {
@Relationship(type="RESIDES_AT", direction=Relationship.OUTGOING)
Set<ResidesAt> residesAt = new HashSet<>();
...
}
을 그리고 실행에 내가 좋아하는 뭔가를 할 것이다 : 그러나
Company createCompany = new Company("Top Mechanic");
Person createPerson = new Person("John", "Doe");
Address createAddress = new Address("John's Home", "123 Mystery Lane", null, "Big City", "UT", "84123", null, "Occupied");
createPerson.residesAt(createAddress, "Home Owner");
createCompany.residesAt(createAddress, "John's Business Mailing Address");
companyRepository.save(createCompany);
personRepository.save(createPerson);
을;
이2017-09-29 16:26:26.832 WARN 7564 --- [ main] org.neo4j.ogm.metadata.ClassInfo : Failed to find an @StartNode on trn.justin.model.relationships.ResidesAt
2017-09-29 16:26:26.832 WARN 7564 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'companyService': Unsatisfied dependency expressed through field 'companyRepository'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'companyRepository': Unsatisfied dependency expressed through method 'setSession' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.data.neo4j.transaction.SharedSessionCreator#0': Cannot resolve reference to bean 'sessionFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.neo4j.ogm.session.SessionFactory]: Factory method 'sessionFactory' threw exception; nested exception is java.lang.NullPointerException
2017-09-29 16:26:26.832 INFO 7564 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2017-09-29 16:26:26.848 WARN 7564 --- [ main] o.s.b.c.e.EventPublishingRunListener : Error calling ApplicationEventListener
java.lang.ClassCastException: org.springframework.boot.context.event.ApplicationFailedEvent cannot be cast to org.springframework.boot.web.context.WebServerInitializedEvent