【发布时间】:2020-02-03 09:01:22
【问题描述】:
我对 Spring Data Neo4j 和 OGM 有疑问。当我第一次创建节点时,没问题,但是如果我刷新该页面,我会收到此错误:
Cypher 执行失败,代码为“Neo.ClientError.Schema.ConstraintValidationFailed”:节点 (126) 已存在,标签为
Country,属性name= 'Country-1'。
我在网上搜索并阅读了很多关于 equals 和 hashCode 的文档,但没有一个有帮助。这是我的课程:
public abstract class Place {
@Id
@GeneratedValue(strategy = UuidStrategy.class)
private String id ;
private String name ;
public String getId(){return id ;}
}
@Getter
@Setter
@NodeEntity(label = "Country")
@CompositeIndex(unique = true , properties = "name")
public class Country extends Place {
private String label = "Country";
public Country() {}
@Override
public int hashCode() {
int result = label == null ? 1 : label.hashCode();
result = 31 * result + this.getName() == null ? 0 : this.getName().hashCode();
result = 31 * result + this.getId() == null ? 0 : this.getId().hashCode();
return result;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Country)) {
return false;
}
Country that = (Country) o ;
return this.getName().equals(that.getName())
&& this.getId().equals(that.getId())
&& this.getLabel().equals(that.getLabel());
}
}
存储库是默认的。据我所知,这是一个平等检查的问题,但我该如何解决这个问题?
【问题讨论】:
-
嘿,您的项目中是否还有其他类正在扩展 Places 类。
标签: neo4j spring-data-neo4j neo4j-ogm