Hi,

This is a cross post from 
http://forum.springsource.org/showthread.php?120071-Inheritance-in-spring-data-neo4j
 


I'm using spring-data-neo4j in an object model with inheritance, with a 
base class Video, a subclass YoutubeVideo and a VideoRepository. The 
Video base class contains a field "id", which uses @Indexed

When I save a Video instance with an id field a call to 
VideoRepository.findById returns the object.

However, if I save a YoutubeVideo, the same call to 
VideoRepository.findById returns null.

Why do I get a different behavior here?

Here are the model classes:


@NodeEntity
public class Video {
@GraphId
public Long nodeId;
@Indexed
public String id;
@Indexed
public String title;
public String description;
public String originalTitle;
public String thumbnailUrl;
}
public class YoutubeVideo extends Video {
public String youtubeId;
}

public interface VideoRepository extends GraphRepository<Video>, 
NamedIndexRepository<Video>,
RelationshipOperationsRepository<Video> {
Video findById(String id);
}



Here is the test code I use. The second test fails.

@Test
public void findVideo() {
    Video video = new Video();
video.setId("test.new");

videoRepository.save(video);
Video existing = videoRepository.findById(video.getId());
assertNotNull(existing);

videoRepository.delete(existing);
existing = videoRepository.findById(video.getId());
assertNull(existing);
}

@Test
public void findVideoSubclass() {
YoutubeVideo video = new YoutubeVideo();
video.setId("test.subclass");

videoRepository.save(video);
Video existing = videoRepository.findById(video.getId());
assertNotNull(existing); <--------- fails

videoRepository.delete(existing);
existing = videoRepository.findById(video.getId());
assertNull(existing);
}

-- 
Nils Kaiser
MSc in Information Systems

_______________________________________________
NOTICE: THIS MAILING LIST IS BEING SWITCHED TO GOOGLE GROUPS, please register 
and consider posting at https://groups.google.com/forum/#!forum/neo4j

Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to