可以将超类型保存为标签之一的Neo4j的功能非常棒,但我无法像预期的那样检索一组超类型。
超类称为服务
@NodeEntity
public abstract class Service implements java.io.Serializable {...}
子类名为HostingService
@NodeEntity
public class HostingService extends Service implements java.io.Serializable{
@GraphId Long id;
....
}
还有一个名为SystemCatalog的类拥有一组服务
@NodeEntity
public class SystemCatalog implements java.io.Serializable{
@GraphId Long id;
....
@Relationship(type="SERVICE", direction=Relationship.OUTGOING)
private Set<Service> services = new HashSet<>();
}
保存测试方法顺利,neo4j浏览器显示HostingService与标签(Service和HostingService)一起保存
@Test
public void testSaveService(){
SystemCatalog sys = new SystemCatalog();
sys.setSystemName("Test Service");
HostingService host = new HostingService();
host.setCostCenter("Cost Center A");
sys.getServices().add(host);
Long id = systemCatalogRepository.save(sys).getId();
System.out.println(id);
}
检索到的测试方法出错,返回的SystemCatalog根本没有任何服务
@Test
public void testGetService(){
SystemCatalog sys2 = systemCatalogRepository.findOne(new Long(243));
System.out.println(sys2);
}