cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Removing a relationship

So I have a quite functional setup that will add nodes as needed without duplication, however I'm at a total loss on how to remove a relationship between two nodes via save.

Using og, 3.1.7

@NodeEntity
public class Person extends Entity {

   @Relationship(type = RelationshipTypes.CLOTHINGREL)
   private Set<Clothing> clothing;

    @Id
   private String name;

   public Person() {
   }

   public Person(@JsonProperty(value = "name") String name) {
       this.name = name != null ? name : "";

       this.clothing = new HashSet<>();
   }

   public void addClothing(Clothing cloth) {
       this.clothing.add(cloth);
   }

   public Set<Clothing> getClothing() {
       return clothing;
   }

   public void setClothing(Set<Clothing> clothing) {
       this.clothing = clothing;
   }

}


@NodeEntity
public class Clothing extends Entity {


   @Id
   private String clothing;

   @Relationship(type= RelationshipTypes.CLOTHINGREL, direction=Relationship.INCOMING)
   Set<Person> persons;

   Clothing(){}

   Clothing(@JsonProperty(value = "clothing") String clothing){
       this.clothing = clothing != null ? clothing : "";
       this.persons = new HashSet<>();
   }

   public String getClothing() {
       return clothing;
   }

   public void setClothing(String clothing) {
       this.clothing = clothing;
   }

   public Set<Person> getPersons() {
       return persons;
   }

   public void setPersons(Set<Person> persons) {
       this.persons = persons;
   }

   public void addPerson(Person person){
       this.persons.add(person);
   }
}


   @Test
   public void updateTest() throws IOException {
       NeoSessionProvider nsp = getSession();

       Person pe = nsp.get().load(Person.class, "jeff", 2);

      pe.setClothing(new HashSet<Clothing>());
       nsp.get().save(pe);
       nsp.get().clear();
   }
0 REPLIES 0