Nils,

Answered there, copying it here for completeness :)

Michael

If you use videoRepository.findById() it only looks on the video-repository 
level (as it only knows about that). It creates a cypher query that uses:

start n = node:Video(id={0}) return n;

There is the @Indexed(level=IndexType.INSTANCE) attribute that makes the field 
being indexed at the instance-class level and not at the level of the declaring 
class of the field. I'm just thinking about adding another option that says 
IndexType.HIERARCHY that adds an index-entry on all levels.

Could you please raise a JIRA issue for this. 

Thanks a lot

Michael

Am 14.12.2011 um 09:17 schrieb Nils Kaiser:

> 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

_______________________________________________
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