1

当我尝试保存具有 @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 Data “级联”实体的持久性,我唯一关心的是用其原始属性和相关实体填充被测实体,保存它,然后检索它以查看数据是否存在。

这对我最初的几个没有@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 存储库保存之前调试模式下变量状态的图像。请注意,信仰实体已完全填充!

在此处输入图像描述

还有用于测试的代码:

//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 相关的所有实体(例如,命题、假设等)来停止出现此错误。不过,我不确定为什么这解决了这个问题。

回答迈克尔评论:迈克尔,你是说应该在 Belief 类本身中定义 rel 类型(而不是使用 @RelatedToVia 注释的 type 属性),否则我应该使用 template.createRelationshipBetween?我尝试使用 @RelationshipEntity 类型属性,但问题仍然存在。起作用的是在@Startnode(BasicProbabilityAssignmentFunction)之前保存关系@EndNode(Proposition)。通过这样做,在保存 BasicProbabilityAssignmentFunction 时,可以毫无问题地创建(保存)信念关系。

4

1 回答 1

0

这个问题是已知的。请查看以下链接:

于 2013-08-23T15:13:25.897 回答