Запись обновления SpringBoot + Neo4J OGM - PullRequest
0 голосов
/ 14 октября 2019

У меня возникает очень странная проблема при попытке обновить запись в базе данных. Основной узел обновляется правильно, но связь не создается после его удаления.

У меня есть узел с отношением в базе данныхя пытаюсь обновить его с помощью этого кода

Role roleRecord = findByUuid(uuid);//Get Role Record
Role roleData = new Role();//Create a new role object and update values
roleData.setDescription(role.getDescription());
roleData.setUuid(roleRecord.getUuid());
roleData.setRoleName(roleRecord.getRoleName());
roleData.setLabels(updatedLabelRecord);
deleteRole(roleRecord);// Delete existing role from database
for (Labels label : dbRecord) { //Delete relationship Node
    deleteLabel(label);
}
createRole(roleData);// Then Create role and Label with new Data set

Этот код создает Role запись, но не узел Label (который является отношением), отношение что-то вроде этого

Role->FILTERS_ON->Label

РЕДАКТИРОВАТЬ 1-

Роль - это объект Neo4j

deleteRole - это метод

public void deleteRole(Role roleEntity) {
        roleRepository.delete(roleEntity);
    }

deleteLabel - это метод

public void deleteLabel(com.nokia.nsw.uiv.uam.entities.Labels label) {
        labelRepository.delete(label);

    }

createRole - это метод

public Role createRole(Role role) {
        return roleRepository.save(role);
    }

РЕДАКТИРОВАТЬ 2 - Роль Entity Class

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

import io.swagger.annotations.Api;
@Api(
    tags = "Role",
    description = ""
)

@NodeEntity(label = "com.model.Role")
public class Role implements Serializable {

    private static final long serialVersionUID = -8010543109475083169L;

    private String roleName = null;

    private String description = null;

//  @Relationship(type = "HAS_ROLE", direction="INCOMING")
//  private Tenant tenant;

    @Relationship(type = "FILTERS_ON")
    private List<Labels> labels = new ArrayList<>();

    @JsonIgnore
    private Long id;

    @Id
    @GeneratedValue(strategy = UivUuidStrategy.class)
    @JsonProperty("id")
    private String uuid;

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

//  public Tenant getTenant() {
//      return tenant;
//  }
//
//  public void setTenant(Tenant tenant) {
//      this.tenant = tenant;
//  }

    public List<Labels> getLabels() {
        return labels;
    }

    public void setLabels(List<Labels> labels) {
        this.labels = labels;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

}

Метка Entity Class

import java.io.Serializable;
import java.util.Map;
import java.util.Objects;

import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Properties;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

@NodeEntity(label = "com.model.role.Filter")
public class Labels implements Serializable {

    private static final long serialVersionUID = 1L;

    private String labelName;

    @Properties
    private Map<String, String> match;

    private String access;

    @JsonIgnore
    private Long id;

    @Id
    @GeneratedValue(strategy = UivUuidStrategy.class)
    @JsonProperty("id")
    private String uuid;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public Map<String, String> getMatch() {
        return match;
    }

    public void setMatch(Map<String, String> match) {
        this.match = match;
    }

    public String getLabelName() {
        return labelName;
    }

    public void setLabelName(String labelName) {
        this.labelName = labelName;
    }

    public String getAccess() {
        return access;
    }

    public void setAccess(String access) {
        this.access = access;
    }

    @Override
    public String toString() {
        return "labelName : " + this.labelName;
    }

    @Override
    public boolean equals(Object obj) {
        return (obj instanceof Labels) && this.labelName.equals(((Labels) obj).getLabelName());
    }

    @Override
    public int hashCode() {
        return Objects.hash(labelName);
    }
}
...