Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Neo4j SDN-OGM节点平等性_Neo4j_Spring Data Neo4j_Neo4j Ogm - Fatal编程技术网

Neo4j SDN-OGM节点平等性

Neo4j SDN-OGM节点平等性,neo4j,spring-data-neo4j,neo4j-ogm,Neo4j,Spring Data Neo4j,Neo4j Ogm,我对Spring数据Neo4j和OGM有问题。当我第一次创建一个节点时,这是正常的,但如果我刷新该页面,就会出现以下错误: 密码执行失败,代码为“Neo.ClientError.Schema.ConstraintValidationFailed”:节点(126)已存在,且标签为Country,属性为name=“Country-1” 我在网上搜索了很多关于equals和hashCode的文档,但是没有一个有用。以下是我的课程: public abstract class Place {

我对Spring数据Neo4j和OGM有问题。当我第一次创建一个节点时,这是正常的,但如果我刷新该页面,就会出现以下错误:

密码执行失败,代码为“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());
    }
}

存储库是默认的。据我所知,这是一个平等检查的问题,但我如何解决这个问题?

您通过定义

@CompositeIndex(unique=true,properties=“name”)

您可能还在Neo4j OGM
SessionFactory
配置中启用了自动索引管理器功能。 这与
hashCode
equals
的任何实现无关


这也将解释您面临的行为:第一次运行成功,但相同的操作重复失败。

使用此@CompositeIndex(unique=true,properties=“name”)我将确保不再创建该节点,如果我删除此节点,则每次刷新页面时都会在db中创建相同的节点,我想用ogm的方式来检测,那是同一个节点!在这种情况下,我需要更多的信息当你“刷新页面”时会发生什么。Controller/Service/repository调用或类似调用。@FarjamRamezanpour您是否在同一会话/事务中读取、更改和写入了
Country
节点?您的项目中是否有其他类扩展了Places类。