Hi,
I'm trying to get RelationshipEntities which inherit from a common base class working and have run into an issue. I've pasted below a sample representation of the domain I'm working with and a sample test case showing where I'm having a problem. I'm testing with these classes by adding them to the current cineasts sample project and adding my test case to the existing DomainTest class. I'm using simple mapping (non-aspects).
Any hints would be greatly appreciated!
Code:package org.neo4j.cineasts.domain.test; import org.springframework.data.neo4j.annotation.GraphId; import org.springframework.data.neo4j.annotation.NodeEntity; @NodeEntity public class BasicEntity { @GraphId private Long entityId; /* lots of other common properties here in our real domain */ public BasicEntity() { } public Long getEntityId() { return entityId; } }Code:package org.neo4j.cineasts.domain.test; import org.springframework.data.neo4j.annotation.*; @RelationshipEntity public class BasicRelationship { @GraphId private Long entityId; @Fetch @StartNode private BasicEntity startNode; @Fetch @EndNode private BasicEntity endNode; /* lots of other common properties here in our real domain */ public BasicRelationship() { } public BasicRelationship(Long entityId, BasicEntity startNode, BasicEntity endNode) { this.entityId = entityId; this.startNode = startNode; this.endNode = endNode; } }Code:package org.neo4j.cineasts.domain.test; import org.springframework.data.neo4j.annotation.Fetch; import org.springframework.data.neo4j.annotation.RelatedToVia; import java.util.Set; public class Project extends BasicEntity { @Fetch @RelatedToVia private Set<ProjectDetailRelationship> projectDetailRelationships; public Set<ProjectDetailRelationship> getProjectDetailRelationships() { return projectDetailRelationships; } }Code:package org.neo4j.cineasts.domain.test; import org.neo4j.graphdb.Direction; import org.springframework.data.neo4j.annotation.Fetch; import org.springframework.data.neo4j.annotation.RelatedTo; public class ProjectDetail extends BasicEntity { private String name; @Fetch @RelatedTo(type = ProjectDetailRelationship.TYPE, direction = Direction.INCOMING) private Project parentProject; public ProjectDetail() { } public ProjectDetail(String name) { this.name = name; } public String getName() { return name; } public Project getParentProject() { return parentProject; } }Code:package org.neo4j.cineasts.domain.test; import org.springframework.data.neo4j.annotation.RelationshipType; public class ProjectDetailRelationship extends BasicRelationship { public static final String TYPE = "PROJECT_HAS_PROJECT_DETAIL"; @RelationshipType private String type = TYPE; public ProjectDetailRelationship() { } public ProjectDetailRelationship(Long entityId, Project project, ProjectDetail projectDetail) { super(entityId, project, projectDetail); } }Code://Added to org.neo4j.cineasts.domain.DomainTest @Test public void testInheritanceDomain() { final String validName = "FOO"; GraphRepository<Project> projectRepository = template.repositoryFor(Project.class); GraphRepository<ProjectDetail> projectDetailRepository = template.repositoryFor(ProjectDetail.class); Project project = new Project(); project = projectRepository.save(project); ProjectDetail projectDetail = new ProjectDetail(validName); projectDetailRepository.save(projectDetail); ProjectDetailRelationship projectDetailRelationship = new ProjectDetailRelationship(null, project, projectDetail); template.save(projectDetailRelationship); project.getProjectDetailRelationships().add(projectDetailRelationship); project = projectRepository.save(project); assertEquals(1, count(projectRepository.findAll())); assertEquals(1, count(projectDetailRepository.findAll())); ProjectDetail actualProjectDetail = projectDetailRepository.findAll().iterator().next(); assertEquals(validName, actualProjectDetail.getName()); assertEquals(project.getEntityId(), actualProjectDetail.getParentProject().getEntityId()); //all tests above pass without issue -- the test below fails: expected:<1> but was:<0> Project actualProject = projectRepository.findOne(project.getEntityId()); assertEquals(1, actualProject.getProjectDetailRelationships().size()); } private int count(Iterable iterable) { int count = 0; for (Object object : iterable) { count++; } return count; }


Reply With Quote
