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/2/csharp/321.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 persist()始终创建新节点_Neo4j_Spring Data Neo4j - Fatal编程技术网

Neo4j persist()始终创建新节点

Neo4j persist()始终创建新节点,neo4j,spring-data-neo4j,Neo4j,Spring Data Neo4j,我在SDN 2.0.0.RELEASE和Neo4j 1.5的索引/持久化方面遇到问题 我有一个域类“Word”,它基本上如下所示: @NodeEntity public class Word { @GraphId Long graphId; @Indexed(indexType = IndexType.SIMPLE, indexName = "Word_wordString") private String wordString; @RelatedTo(direction = Direct

我在SDN 2.0.0.RELEASE和Neo4j 1.5的索引/持久化方面遇到问题

我有一个域类“Word”,它基本上如下所示:

@NodeEntity
public class Word {

@GraphId
Long graphId;

@Indexed(indexType = IndexType.SIMPLE, indexName = "Word_wordString")
private String wordString;

@RelatedTo(direction = Direction.INCOMING, elementClass = Sentence.class, type = "HAS")
private Set<Sentence> sentences;

public Word() {
}

public Word(String wordString) {
    setWordString(wordString);
}
}
它应该检查单词是否已经在图中,如果已经在图中,我会更改wordRepository返回的对象的一些属性,然后保留更改(->if(existingWord!=null))。如果单词不在图形中,它只是被持久化(->else)

然而,这总是为每个单词创建一个新节点,即使它存在于图形中。可以说,persist()总是创建一个新节点。 在图形中有两个具有相同字串的单词后,repository方法抛出:

More than one element in org.neo4j.index.impl.lucene.LuceneIndex$1@1181df3. First element is 'Node[45]' and the second element is 'Node[83]'
发生什么事了

我还想知道IndexType.SIMPLE、IndexType.POINT和IndexType.FULLTEXT之间的区别是什么。(它不在API或《良好关系指南》中)

Tobias

请检查以索引名作为第一个参数并传入“Word\u wordString”索引的
findByPropertyValue
是否有帮助。您的存储库还必须扩展NamedIndexRepository`名称。无论如何,存储库都应该自动考虑您的自定义索引名

您还可以尝试省去单独的索引名,然后默认为简单的类名,即自动使用的
Word


你用的是什么词?它们是字母数字字符还是其他字符,比如空格、换行符等?

好吧,我发现了问题:


当我坚持这些单词时,我总是将它们添加到当前句子的“单词”集中,并设置单词的句子属性。我想这就是为什么一些单词被多次保存的原因。

我已经让我的WordRepository扩展了GraphRespository和NamedIndexRepository,并使用了
WordRepository.findByPropertyValue(“Word_wordString”,“wordString”,Word.getWordString())
检查现有单词。除了检查索引的那一行之外,代码与我原来的问题中的代码相同。发生的情况是,第一次持久化一个单词时,索引按预期返回null,新单词被持久化。第二次,索引返回一个对象实例,如预期的那样。然而,第三次,索引抛出与我原来问题相同的异常。因此,我认为persist方法总是在索引中创建一个新节点和/或条目!我将检查单词包含哪些字符,但出于测试目的,我会在初始设置时对它们进行修剪。
More than one element in org.neo4j.index.impl.lucene.LuceneIndex$1@1181df3. First element is 'Node[45]' and the second element is 'Node[83]'