【发布时间】:2015-11-04 11:11:55
【问题描述】:
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);
}
【问题讨论】:
标签: java neo4j spring-data-neo4j spring-data-neo4j-4