The feature of Neo4j that can save super type as one of the labels is really great, but I cannot retrieve a set of the super type as I expected.
The super class is called Service
@NodeEntity
public abstract class Service implements java.io.Serializable {...}
The sub class is called HostingService
@NodeEntity
public class HostingService extends Service implements java.io.Serializable{
@GraphId Long id;
....
}
And there is a class called SystemCatalog to own a set of Service
@NodeEntity
public class SystemCatalog implements java.io.Serializable{
@GraphId Long id;
....
@Relationship(type="SERVICE", direction=Relationship.OUTGOING)
private Set<Service> services = new HashSet<>();
}
The save test method goes well, the neo4j browser shows that the HostingService is saved with both label (Service and 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);
}
The retrieved test method went wrong, the returned SystemCatalog doesn't have any service at all
@Test
public void testGetService(){
SystemCatalog sys2 = systemCatalogRepository.findOne(new Long(243));
System.out.println(sys2);
}