仅当我从数据库中检索实体时,属性上的 @Query 才会检索值。
@NodeEntity
public class Team
{
@GraphId
private Long nodeId;
@RelatedTo (type = "PREVIOUSLY_KNOWN_AS")
private Team previouslyKnownAs;
@Query ("START t=node({self}) MATCH t-[:PREVIOUSLY_KNOWN_AS]-other RETURN other")
private Iterable<Team> aliases;
}
仅当我取消注释该行以从数据库中显式读取它时,以下测试才有效。为什么有必要?我看到查询正在运行,save(t)
但该alias
字段是null
如果我没有通过取消注释该行从数据库中读取它
@Test
public void alias()
{
Team t = new Team();
t.setName("Alpharetta One");
Team prev = new Team();
prev.setName("Previous Name");
teamRepo.save(prev);
t.setPreviouslyKnownAs(prev);
teamRepo.save(t);
//t = teamRepo.findOne(t.getNodeId());//only works if I uncomment
assertNotNull(t.getAliases());
}