2

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);

}
minglight
  • 87
  • 6

1 Answers1

2

This is a bug, your code looks fine.

Please follow https://jira.spring.io/browse/DATAGRAPH-735 to track it.

Luanne
  • 19,145
  • 1
  • 39
  • 51
  • Hi Luanne! Do you know if there is the same bug in spring-data-neo4j `3.3.2.RELEASE` . I'm facing with a similar [issue](https://stackoverflow.com/questions/31948339/spring-data-neo4j-basic-one-to-many-relationship-not-persisting) – troig Aug 12 '15 at 06:14