나는 @RelatedToVia 속성이있는 개체 저장하려고하면 다음과 같은 오류를 받고 있어요 : 그것은 것 같다 위에봄 데이터 Neo4j @RelatedToVia 오류
org.springframework.dao.InvalidDataAccessApiUsageException: Null parameter, startNode=NodeImpl#1, endNode=null, type=DynamicRelationshipType[BPA_PROPOSITION]; nested exception is java.lang.IllegalArgumentException: Null parameter, startNode=NodeImpl#1, endNode=null, type=DynamicRelationshipType[BPA_PROPOSITION]
오류 설명에서 내 RelationshipEntity에 끝 노드가 누락되었습니다. 그러나이 문제는 최악의 부분이며,이 오류가 임의로 발생하기 때문에 사실이 아닙니다.
다음은 시나리오입니다. 내 클래스 매핑을 확인하기 위해 몇 가지 간단한 테스트를 만들고있다. 각 테스트 케이스에 필요한 클래스를 수동으로 생성 한 다음 저장합니다. Spring 데이터는 테스트 대상 엔티티를 프리미티브 속성 및 관련 엔티티로 채우고 저장 한 다음 다시 검색하여 데이터가 있는지 확인하기 만하면됩니다.
이것은 @RelatedToVia 매핑이없는 처음 몇 클래스에는 잘 작동하지만 @RelatedToVia를 사용하는 클래스에는 적합하지 않습니다. 다음은 @RelatedToVia를 사용하는 코드의 일부입니다.
@NodeEntity
public class BasicProbabilityAssignmentFunction {
@GraphId
private Long id;
@RelatedTo(type = RelTypeConstants.BPA_FRAME, direction = Direction.OUTGOING)
private FrameOfDiscernment frameOfDiscernment;
@RelatedToVia(type = RelTypeConstants.BPA_PROPOSITION, direction = Direction.OUTGOING, elementClass = Belief.class)
private Set<Belief> beliefs;
}
@RelationshipEntity
public class Belief {
@GraphId
private Long id;
@StartNode
private BasicProbabilityAssignmentFunction bpaFunction;
@EndNode
private Proposition proposition;
}
@NodeEntity
public class Proposition {
@GraphId
private Long id;
@RelatedTo(type= RelTypeConstants.PROPOSITION_HYPOTHESIS, direction= Direction.OUTGOING)
private Set<Hypothesis> hypotheses;
@RelatedTo(type = RelTypeConstants.FRAME_PROPOSITION, direction = Direction.INCOMING)
private FrameOfDiscernment frameOfDiscernment;
}
플러스, 여기에 바로 BasicProbabilityAssignmentFunction 저장소에 저장 호출하기 전에 모드를 debbuging에서 변수 상태의 이미지입니다. Belief 엔티티가 완전히 채워져 있음을 주목하십시오!
//this just creates an instance with its attributes populated
BasicProbabilityAssignmentFunction bpaFunction = BasicMockFactory.createBpaFunction();
//this is where I get the error.
bpaFunction = bpaFunctionRepository.save(bpaFunction);
하나 더 참고 : 또한 시험에 사용되는 코드
그리고
! BasicProbabilityAssignmentFunction 자체를 저장하기 전에 BasicProbabilityAssignmentFunction과 관련된 모든 항목 (예 : 제안, 가설 등)을 저장하여이 오류가 발생하는 것을 막을 수있었습니다. 그럼에도 불구하고 왜 이것이 문제를 해결했는지 나는 잘 모르겠습니다.
마이클 코멘트 응답 : 마이클, 당신은 확인해 형이 믿음 클래스 자체 (대신 @RelatedToVia 주석의 type 속성을 사용하여)에 정의되어야하거나 내가 template.createRelationshipBetween를 사용해야한다는거야? @RelationshipEntity 유형 속성을 사용하려고했으나 문제가 지속되었습니다. @Startnode (BasicProbabilityAssignmentFunction) 앞에 @EndNode (Proposition) 관계를 저장하는 것이 효과가있었습니다. 이렇게함으로써 BasicProbabilityAssignmentFunction이 저장 될 때 아무런 문제없이 Belief 관계가 생성 (저장)됩니다.
당신이'추가하면 있는지 확인을 Beliefs' 모든 이들 3 개 분야 (시작 노드, 끝 노드와 확인해 -type)이 채워집니다. 그렇지 않으면 관계 엔티티를 직접 저장하거나 'template.createRelationshipBetween()'을 사용하십시오. –