Neo4j 可以将超类型保存为标签之一的功能确实很棒,但是我无法按预期检索一组超类型。
超类称为Service
@NodeEntity
public abstract class Service implements java.io.Serializable {...}
子类称为 HostingService
@NodeEntity
public class HostingService extends Service implements java.io.Serializable{
@GraphId Long id;
....
}
并且有一个类叫做 SystemCatalog 拥有一套 Service
@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);
}