Announcement Announcement Module
Collapse
No announcement yet.
neo4j - Multiple RelationshipEntities of the same Type Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • neo4j - Multiple RelationshipEntities of the same Type

    Hi,

    I'm trying to get multiple RelationshipEntities of the same type (with different attribute values on the RelationshipEntity instances) between the same two nodes working and have run into an issue. I've pasted below a test case I added to the current cineasts sample project which illustrates the issue I'm seeing. I'm using simple mapping (non-aspects).

    I'm not sure if I'm just misunderstanding something or if this might actually be a bug in SDN. If its a bug I would be happy to open a JIRA.

    Any hints would be greatly appreciated!

    Note -- I've included two snippets below -- one just showing the "core" issue I'm seeing WRT multiple RelationshipEntities of the same type between the same two nodes, and another with more extended verifications which seem to reveal some other issues which I don't quite understand...

    Thanks!

    "Core" Issue Sample
    Code:
        //Added to org.neo4j.cineasts.domain.DomainTest
        @Test
        public void actorCanPlayMultipleRolesInTheSameMovie() {
            String austinPowers = "Austin Powers";
            String drEvil = "Dr. Evil";
            String fatBastard = "Fat Bastard";
    
            Actor mikeMyers = template.save(new Actor("1", "Mike Myers"));
            Movie theSpyWhoShaggedMe = template.save(new Movie("1", "Austin Powers: The Spy Who Shagged Me"));
    
            Role roleAustinPowers = mikeMyers.playedIn(theSpyWhoShaggedMe, austinPowers);
            template.save(roleAustinPowers);
            Role roleDrEvil = mikeMyers.playedIn(theSpyWhoShaggedMe, drEvil);
            template.save(roleDrEvil);
            Role roleFatBastard = mikeMyers.playedIn(theSpyWhoShaggedMe, fatBastard);
            template.save(roleFatBastard);
    
            Movie foundTheSpyWhoShaggedMe = this.movieRepository.findById("1");
            assertEquals("created and looked up movie equal", theSpyWhoShaggedMe, foundTheSpyWhoShaggedMe);
            assertEquals("created and looked up movie name match", theSpyWhoShaggedMe.getTitle(), foundTheSpyWhoShaggedMe.getTitle());
    
            List<Role> expectedRoles = Arrays.asList(roleAustinPowers, roleDrEvil, roleFatBastard);
            Map<Role, Role> foundMovieRoles = mapRoles(foundTheSpyWhoShaggedMe.getRoles());
            for (Role expectedRole : expectedRoles) {
                Role foundMovieRole = foundMovieRoles.get(expectedRole);
    
                assertThat("found movie contains expected role", foundMovieRole, is(notNullValue()));
                assertEquals("found movie role contains expected actor", foundMovieRole.getActor(), mikeMyers);
                assertEquals("found movie role contains expected movie", foundMovieRole.getMovie(), theSpyWhoShaggedMe);
            }
        }
    "Extended" Issue Sample
    Code:
        //Added to org.neo4j.cineasts.domain.DomainTest
        @Test
        public void actorCanPlayMultipleRolesInTheSameMovie_extendedValidation() {
            String austinPowers = "Austin Powers";
            String drEvil = "Dr. Evil";
            String fatBastard = "Fat Bastard";
    
            Actor mikeMyers = template.save(new Actor("1", "Mike Myers"));
            Movie theSpyWhoShaggedMe = template.save(new Movie("1", "Austin Powers: The Spy Who Shagged Me"));
    
            Role roleAustinPowers = mikeMyers.playedIn(theSpyWhoShaggedMe, austinPowers);
            template.save(roleAustinPowers);
            Role roleDrEvil = mikeMyers.playedIn(theSpyWhoShaggedMe, drEvil);
            template.save(roleDrEvil);
            Role roleFatBastard = mikeMyers.playedIn(theSpyWhoShaggedMe, fatBastard);
            template.save(roleFatBastard);
    
            Movie foundTheSpyWhoShaggedMe = this.movieRepository.findById("1");
            Actor foundMikeMyers = this.actorRepository.findById("1");
    
            //NOTE: foundMikeMyers is null at this point -- I dont understand why...
    
            assertEquals("created and looked up movie equal", theSpyWhoShaggedMe, foundTheSpyWhoShaggedMe);
            assertEquals("created and looked up movie name match", theSpyWhoShaggedMe.getTitle(), foundTheSpyWhoShaggedMe.getTitle());
    
            List<Role> expectedRoles = Arrays.asList(roleAustinPowers, roleDrEvil, roleFatBastard);
            Map<Role, Role> foundMovieRoles = mapRoles(foundTheSpyWhoShaggedMe.getRoles());
            Map<Role, Role> foundActorRoles = mapRoles(IteratorUtil.asCollection(foundMikeMyers.getRoles()));
            for (Role expectedRole : expectedRoles) {
                Role foundMovieRole = foundMovieRoles.get(expectedRole);
                Role foundActorRole = foundActorRoles.get(expectedRole);
    
                assertThat("found movie contains expected role", foundMovieRole, is(notNullValue()));
                assertEquals("found movie role contains expected actor", mikeMyers, foundMovieRole.getActor());
                assertEquals("found movie role contains expected movie", theSpyWhoShaggedMe, foundMovieRole.getMovie());
                assertEquals("found movie role actor name matches", mikeMyers.getName(), foundMovieRole.getActor().getName());
                assertEquals("found movie role movie title matches", theSpyWhoShaggedMe.getTitle(), foundMovieRole.getMovie().getTitle());
    
                assertThat("found actor contains expected role", foundActorRole, is(notNullValue()));
                assertEquals("found actor role contains expected actor", mikeMyers, foundActorRole.getActor());
                assertEquals("found actor role contains expected movie", theSpyWhoShaggedMe, foundActorRole.getMovie());
                assertEquals("found actor role actor name matches", mikeMyers.getName(), foundActorRole.getActor().getName());
                assertEquals("found actor role movie title matches", theSpyWhoShaggedMe.getTitle(), foundActorRole.getMovie().getTitle());
            }
        }
    Code:
        //Added to org.neo4j.cineasts.domain.DomainTest
        private Map<Role, Role> mapRoles(Collection<Role> roles) {
            Map<Role, Role> rolesMap = new HashMap<Role, Role>();
            for (Role role : roles) {
                rolesMap.put(role, role);
            }
            return rolesMap;
        }

  • #2
    Anyone have any thoughts on this issue? Should I just go ahead and open up a SDN JIRA issue for it?

    Thanks!

    Comment


    • #3
      Jesse,

      In general SDN limits it to one relationship of one type between two entities to make it possible for the framework to reason about it and detect differences.

      There have been some requests to alleviate that.

      Please issue a Request or update an existing one pointing to this thread.

      Thanks for reporting it with such a comprehensive test.

      Michael

      Comment


      • #4
        Thanks Michael.

        I didn't see any existing JIRA's for it so I went ahead and created a new one:

        https://jira.springsource.org/browse/DATAGRAPH-225

        Comment

        Working...
        X