{"action":"closed","issue":{"url":"https://api.github.com/repos/spring-projects/spring-data-neo4j/issues/266","repository_url":"https://api.github.com/repos/spring-projects/spring-data-neo4j","labels_url":"https://api.github.com/repos/spring-projects/spring-data-neo4j/issues/266/labels{/name}","comments_url":"https://api.github.com/repos/spring-projects/spring-data-neo4j/issues/266/comments","events_url":"https://api.github.com/repos/spring-projects/spring-data-neo4j/issues/266/events","html_url":"https://github.com/spring-projects/spring-data-neo4j/issues/266","id":66401676,"number":266,"title":"Nodes can't build relationships from different direction ","user":{"login":"tdppro","id":6672432,"avatar_url":"https://avatars.githubusercontent.com/u/6672432?v=3","gravatar_id":"","url":"https://api.github.com/users/tdppro","html_url":"https://github.com/tdppro","followers_url":"https://api.github.com/users/tdppro/followers","following_url":"https://api.github.com/users/tdppro/following{/other_user}","gists_url":"https://api.github.com/users/tdppro/gists{/gist_id}","starred_url":"https://api.github.com/users/tdppro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tdppro/subscriptions","organizations_url":"https://api.github.com/users/tdppro/orgs","repos_url":"https://api.github.com/users/tdppro/repos","events_url":"https://api.github.com/users/tdppro/events{/privacy}","received_events_url":"https://api.github.com/users/tdppro/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2015-04-05T04:43:51Z","updated_at":"2016-08-02T15:22:04Z","closed_at":"2016-08-02T15:22:04Z","body":"\r\nI have five classes as below:\r\n```java\r\n@NodeEntity\r\npublic class Person {\r\n\r\n\t@GraphId\r\n\tLong id;\r\n\r\n\tpublic String name;\r\n\t\r\n\tpublic String sex;\r\n\r\n\tpublic Person() {\r\n\t}\r\n\r\n\tpublic Person(String name, String sex) {\r\n\t\tthis.name = name;\r\n\t\tthis.sex = sex;\r\n\t}\r\n\r\n\t@RelatedTo(type = \"RATED\", direction = Direction.OUTGOING)\r\n\t@Fetch\r\n\tpublic Set<Movie> ratedMovies;\r\n\r\n\t@RelatedToVia(type = \"RATED\", direction = Direction.OUTGOING)\r\n\t@Fetch\r\n\tpublic Set<Rating> ratings;\r\n\t\r\n\tpublic Rating rateMovie(Movie movie, int rate) {\r\n\t\tRating rating = new Rating(rate, this, movie);\r\n\t\tratings.add(rating);\r\n\t\treturn rating;\r\n\t}\r\n\r\n\tpublic Long getId() {\r\n\t\treturn id;\r\n\t}\r\n\r\n\tpublic void setId(Long id) {\r\n\t\tthis.id = id;\r\n\t}\r\n\r\n\tpublic String getName() {\r\n\t\treturn name;\r\n\t}\r\n\r\n\tpublic void setName(String name) {\r\n\t\tthis.name = name;\r\n\t}\r\n\r\n\tpublic String getSex() {\r\n\t\treturn sex;\r\n\t}\r\n\r\n\tpublic void setSex(String sex) {\r\n\t\tthis.sex = sex;\r\n\t}\r\n\r\n\tpublic Set<Movie> getRatedMovies() {\r\n\t\treturn ratedMovies;\r\n\t}\r\n\r\n\tpublic void setRatedMovies(Set<Movie> ratedMovies) {\r\n\t\tthis.ratedMovies = ratedMovies;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic int hashCode() {\r\n\t\tfinal int prime = 31;\r\n\t\tint result = 1;\r\n\t\tresult = prime * result + ((id == null) ? 0 : id.hashCode());\r\n\t\tresult = prime * result + ((name == null) ? 0 : name.hashCode());\r\n\t\tresult = prime * result + ((sex == null) ? 0 : sex.hashCode());\r\n\t\treturn result;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic boolean equals(Object obj) {\r\n\t\tif (this == obj)\r\n\t\t\treturn true;\r\n\t\tif (obj == null)\r\n\t\t\treturn false;\r\n\t\tif (getClass() != obj.getClass())\r\n\t\t\treturn false;\r\n\t\tPerson other = (Person) obj;\r\n\t\tif (id == null) {\r\n\t\t\tif (other.id != null)\r\n\t\t\t\treturn false;\r\n\t\t} else if (!id.equals(other.id))\r\n\t\t\treturn false;\r\n\t\tif (name == null) {\r\n\t\t\tif (other.name != null)\r\n\t\t\t\treturn false;\r\n\t\t} else if (!name.equals(other.name))\r\n\t\t\treturn false;\r\n\t\tif (sex == null) {\r\n\t\t\tif (other.sex != null)\r\n\t\t\t\treturn false;\r\n\t\t} else if (!sex.equals(other.sex))\r\n\t\t\treturn false;\r\n\t\treturn true;\r\n\t}\r\n}\r\n```\r\n\r\n```java\r\npublic interface PersonRepository extends CrudRepository<Person, String> {\r\n\tPerson findByName(String name);\r\n}\r\n```\r\n```java\r\n@NodeEntity\r\npublic class Movie {\r\n\r\n\t@GraphId\r\n\tprivate Long id;\r\n\r\n\tprivate String title;\r\n\t\r\n\tprivate String releaseDate;\r\n\t\r\n\t@RelatedTo(type = \"RATED\", direction = Direction.INCOMING)\r\n\t@Fetch\r\n\tpublic Set<Person> ratedPerson;\r\n\t\r\n\t@RelatedToVia(type = \"RATED\", direction = Direction.INCOMING)\r\n\t@Fetch\r\n\tpublic Set<Rating> ratings;\r\n\r\n\tpublic Movie() {\r\n\t}\r\n\r\n\tpublic Movie(String title, String releaseDate) {\r\n\t\tthis.title = title;\r\n\t\tthis.releaseDate = releaseDate;\r\n\t}\r\n\t\r\n\tpublic Rating addRate(Person person, int rate) {\r\n\t\tRating rating = new Rating(rate, person, this);\r\n\t\tratings.add(rating);\r\n\t\treturn rating;\r\n\t}\r\n\r\n\tpublic Long getId() {\r\n\t\treturn id;\r\n\t}\r\n\r\n\tpublic void setId(Long id) {\r\n\t\tthis.id = id;\r\n\t}\r\n\r\n\tpublic String getTitle() {\r\n\t\treturn title;\r\n\t}\r\n\r\n\tpublic void setTitle(String title) {\r\n\t\tthis.title = title;\r\n\t}\r\n\r\n\tpublic String getReleaseDate() {\r\n\t\treturn releaseDate;\r\n\t}\r\n\r\n\tpublic void setReleaseDate(String releaseDate) {\r\n\t\tthis.releaseDate = releaseDate;\r\n\t}\r\n\r\n\tpublic Set<Person> getRatedPerson() {\r\n\t\treturn ratedPerson;\r\n\t}\r\n\r\n\tpublic void setRatedPerson(Set<Person> ratedPerson) {\r\n\t\tthis.ratedPerson = ratedPerson;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic int hashCode() {\r\n\t\tfinal int prime = 31;\r\n\t\tint result = 1;\r\n\t\tresult = prime * result + ((id == null) ? 0 : id.hashCode());\r\n\t\tresult = prime * result\r\n\t\t\t\t+ ((ratedPerson == null) ? 0 : ratedPerson.hashCode());\r\n\t\tresult = prime * result\r\n\t\t\t\t+ ((releaseDate == null) ? 0 : releaseDate.hashCode());\r\n\t\tresult = prime * result + ((title == null) ? 0 : title.hashCode());\r\n\t\treturn result;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic boolean equals(Object obj) {\r\n\t\tif (this == obj)\r\n\t\t\treturn true;\r\n\t\tif (obj == null)\r\n\t\t\treturn false;\r\n\t\tif (getClass() != obj.getClass())\r\n\t\t\treturn false;\r\n\t\tMovie other = (Movie) obj;\r\n\t\tif (id == null) {\r\n\t\t\tif (other.id != null)\r\n\t\t\t\treturn false;\r\n\t\t} else if (!id.equals(other.id))\r\n\t\t\treturn false;\r\n\t\tif (ratedPerson == null) {\r\n\t\t\tif (other.ratedPerson != null)\r\n\t\t\t\treturn false;\r\n\t\t} else if (!ratedPerson.equals(other.ratedPerson))\r\n\t\t\treturn false;\r\n\t\tif (releaseDate == null) {\r\n\t\t\tif (other.releaseDate != null)\r\n\t\t\t\treturn false;\r\n\t\t} else if (!releaseDate.equals(other.releaseDate))\r\n\t\t\treturn false;\r\n\t\tif (title == null) {\r\n\t\t\tif (other.title != null)\r\n\t\t\t\treturn false;\r\n\t\t} else if (!title.equals(other.title))\r\n\t\t\treturn false;\r\n\t\treturn true;\r\n\t}\r\n}\r\n```\r\n```java\r\npublic interface MovieRepository extends CrudRepository<Movie, String> {\r\n}\r\n``` \r\n```java\r\n@RelationshipEntity(type=\"RATED\")\r\npublic class Rating {\r\n\r\n\t@GraphId\r\n\tprivate Long id;\r\n\t\r\n\tprivate int rate;\r\n\t\r\n\t@StartNode\r\n\tprivate Person person;\r\n\t\r\n\t@EndNode\r\n\tprivate Movie movie;\r\n\r\n\tpublic Rating() {\r\n\t}\r\n\r\n\r\n\tpublic Rating(int rate, Person person, Movie movie) {\r\n\t\tsuper();\r\n\t\tthis.rate = rate;\r\n\t\tthis.person = person;\r\n\t\tthis.movie = movie;\r\n\t}\r\n\r\n\r\n\tpublic Long getId() {\r\n\t\treturn id;\r\n\t}\r\n\r\n\tpublic void setId(Long id) {\r\n\t\tthis.id = id;\r\n\t}\r\n\r\n\tpublic int getRate() {\r\n\t\treturn rate;\r\n\t}\r\n\r\n\tpublic void setRate(int rate) {\r\n\t\tthis.rate = rate;\r\n\t}\r\n\r\n\tpublic Person getPerson() {\r\n\t\treturn person;\r\n\t}\r\n\r\n\tpublic void setPerson(Person person) {\r\n\t\tthis.person = person;\r\n\t}\r\n\r\n\tpublic Movie getMovie() {\r\n\t\treturn movie;\r\n\t}\r\n\r\n\tpublic void setMovie(Movie movie) {\r\n\t\tthis.movie = movie;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic int hashCode() {\r\n\t\tfinal int prime = 31;\r\n\t\tint result = 1;\r\n\t\tresult = prime * result + ((id == null) ? 0 : id.hashCode());\r\n\t\tresult = prime * result + rate;\r\n\t\treturn result;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic boolean equals(Object obj) {\r\n\t\tif (this == obj)\r\n\t\t\treturn true;\r\n\t\tif (obj == null)\r\n\t\t\treturn false;\r\n\t\tif (getClass() != obj.getClass())\r\n\t\t\treturn false;\r\n\t\tRating other = (Rating) obj;\r\n\t\tif (id == null) {\r\n\t\t\tif (other.id != null)\r\n\t\t\t\treturn false;\r\n\t\t} else if (!id.equals(other.id))\r\n\t\t\treturn false;\r\n\t\tif (rate != other.rate)\r\n\t\t\treturn false;\r\n\t\treturn true;\r\n\t}\t\r\n}\r\n```\r\n\r\n```java\r\n@SpringBootApplication\r\npublic class Application implements CommandLineRunner {\r\n\r\n\t@Configuration\r\n\t@EnableNeo4jRepositories(basePackages = \"com.tdp.apps.spring_neo4j_demo\")\r\n\tstatic class ApplicationConfig extends Neo4jConfiguration {\r\n\r\n\t\tpublic ApplicationConfig() {\r\n\t\t\tsetBasePackage(\"com.tdp.apps.spring_neo4j_demo\");\r\n\t\t}\r\n\r\n\t\t@Bean\r\n\t\tGraphDatabaseService graphDatabaseService() {\r\n\t\t\treturn new GraphDatabaseFactory()\r\n\t\t\t\t\t.newEmbeddedDatabase(\"accessingdataneo4j.db\");\r\n\t\t}\r\n\t}\r\n\r\n\t@Autowired\r\n\tPersonRepository personRepository;\r\n\t@Autowired\r\n\tMovieRepository movieRepository;\r\n\r\n\t@Autowired\r\n\tGraphDatabase graphDatabase;\r\n\r\n\tpublic void run(String... args) throws Exception {\r\n\r\n\t\tPerson greg = new Person(\"Greg\", \"male\");\r\n\t\tPerson roy = new Person(\"Roy\", \"female\");\r\n\t\tPerson craig = new Person(\"Craig\", \"male\");\r\n\t\t\r\n\t\tMovie movie1 = new Movie(\"movie1\", \"1997\"); \r\n\t\tMovie movie2 = new Movie(\"movie2\", \"1998\"); \r\n\t\tMovie movie3 = new Movie(\"movie3\", \"1999\"); \r\n\r\n\t\tTransaction tx = graphDatabase.beginTx();\r\n\t\ttry {\r\n\t\t\tgreg = personRepository.save(greg);\r\n\t\t\troy = personRepository.save(roy);\r\n\t\t\tcraig = personRepository.save(craig);\r\n\t\t\t\r\n\t\t\tmovie1 = movieRepository.save(movie1);\r\n\t\t\tmovie2 = movieRepository.save(movie2);\r\n\t\t\tmovie3 = movieRepository.save(movie3);\r\n\r\n\t\t\tgreg.rateMovie(movie1, 3);\r\n\t\t\tgreg.rateMovie(movie2, 4);\r\n\t\t\tgreg = personRepository.save(greg);\r\n\t\t\t\r\n\t\t\troy.rateMovie(movie2, 5);\r\n\t\t\troy.rateMovie(movie3, 2);\r\n\t\t\troy = personRepository.save(roy);\r\n\t\t\t\r\n\t\t\tmovie2.addRate(craig, 1);\r\n\t\t\tmovie2 = movieRepository.save(movie2);\t\t\t\r\n\t\t\ttx.success();\r\n\t\t} finally {\r\n\t\t\ttx.close();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static void main(String[] args) throws Exception {\r\n\t\tFileUtils.deleteRecursively(new File(\"accessingdataneo4j.db\"));\r\n\r\n\t\tSpringApplication.run(Application.class, args);\r\n\t}\r\n}\r\n``` \r\nI want to build the relations greg->movie1 grep->movie2  roy->movie2 roy->movie3 and build the relation from moive2 to craig. So I use the code below:\r\n```java \r\ntry {\r\n\t\t\tgreg = personRepository.save(greg);\r\n\t\t\troy = personRepository.save(roy);\r\n\t\t\tcraig = personRepository.save(craig);\r\n\t\t\t\r\n\t\t\tmovie1 = movieRepository.save(movie1);\r\n\t\t\tmovie2 = movieRepository.save(movie2);\r\n\t\t\tmovie3 = movieRepository.save(movie3);\r\n\r\n\t\t\tgreg.rateMovie(movie1, 3);\r\n\t\t\tgreg.rateMovie(movie2, 4);\r\n\t\t\tgreg = personRepository.save(greg);\r\n\t\t\t\r\n\t\t\troy.rateMovie(movie2, 5);\r\n\t\t\troy.rateMovie(movie3, 2);\r\n\t\t\troy = personRepository.save(roy);\r\n\t\t\t\r\n\t\t\tmovie2.addRate(craig, 1);\r\n\t\t\tmovie2 = movieRepository.save(movie2);\t\t\t\r\n\t\t\ttx.success();\r\n\t\t} finally {\r\n\t\t\ttx.close();\r\n\t\t}\r\n```\r\nBut the result shows as below\r\n![graph](https://cloud.githubusercontent.com/assets/6672432/6993144/b629c5e4-db1d-11e4-8ed0-156d3e8a8052.png)\r\nThe people have no relations with movie2 . I don't know why . Can you help me to handle it ? thanks"}}
{"actor":{"display_login":"mangrish"}}