首页 文章

Neo4j:节点上的MissingIndexException

提问于
浏览
0

我正在尝试在Scala中设置Spring-Data-Neo4j项目的框架 . 当我运行JUnit测试时,我得到一个MissingIndexException,我真的没有任何线索的原因 . 我之前使用纯Java而不是scala实体/测试中的相同配置(和依赖项)成功运行了相同的测试 .

任何帮助都可以 .

(scala)持久化实体:

@NodeEntity
class User extends Identifiable {

    def this(email: String = null, name: String = null) = {
        this()
        this.email = email
        this.name = name
    }

    @Indexed
    var name: String = _

    @Indexed (unique = true)
    var email: String = _

    @Fetch
    @RelatedTo(`type` = "IS_A", direction = Direction.BOTH)
    var agent: Agent = new Agent
}

这是(仍然是java)存储库接口:

public interface UserRepository extends GraphRepository<User> {
    @Query("start n=node:User(email={0}) return count(*)")
    int count(String email);

    User findByEmail(String email);
}

我运行的JUnit测试:

@Test
@Transactional
def testCountEmails = {
    assertEquals(0, userRepository.count("mail"))
    userRepository.save(new User(email = "mail"))
    assertEquals(1, userRepository.count("mail"))
}

日志的摘录:

[main] DEBUG org.springframework.data.neo4j.support.query.CypherQueryEngineImpl - Executing cypher query: MATCH (ref:ReferenceNode {name:{name}}) RETURN ref params {name=root}
[main] DEBUG org.springframework.data.neo4j.support.query.CypherQueryEngineImpl - Executing cypher query: match (n) with n limit 1 set n:`SDN_LABEL_STRATEGY` remove n:`SDN_LABEL_STRATEGY` return count(*) params {}
[main] DEBUG org.springframework.data.neo4j.support.schema.SchemaIndexProvider - CREATE CONSTRAINT ON (n:`User`) ASSERT n.`email` IS UNIQUE
[main] DEBUG org.springframework.data.neo4j.support.query.CypherQueryEngineImpl - Executing cypher query: CREATE CONSTRAINT ON (n:`User`) ASSERT n.`email` IS UNIQUE params {}
[main] DEBUG org.springframework.data.neo4j.support.schema.SchemaIndexProvider - CREATE INDEX ON :`User`(`name`)
[main] DEBUG org.springframework.data.neo4j.support.query.CypherQueryEngineImpl - Executing cypher query: CREATE INDEX ON :`User`(`name`) params {}

我得到的错误:

org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement start n=node:User(email={0}) return count(*); nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement start n=node:User(email={0}) return count(*); nested exception is org.neo4j.cypher.MissingIndexException: Index `User` does not exist

1 回答

  • 1

    所以你可能使用Cypher 2.0,并查看你的查询,你没有MATCH - 只是一个START和一个RETURN . 所以,首先,我甚至不确定这是合法的,但你说它之前就已经开始......我从未见过它 . :)

    也就是说,我很确定START子句使用遗留索引,看起来你正试图将用户视为标签(这是Neo4j 2.x的新功能) . 因此,当SDN创建模式索引(以“name”和“email”作为键)时,START语句将尝试访问不存在的“User”的旧索引 .

    也许尝试这个作为查询,让我们知道它是怎么回事:

    MATCH (n:User {email: <whatever>}) RETURN count(*);
    

    还要确保正在处理您的参数化 .

    (如果我对此有任何疑问,请随时纠正我 . )

    HTH

相关问题