简体   繁体   English

Neo4j:节点上的MissingIndexException

[英]Neo4j: MissingIndexException on a Node

I'm trying to setup a skeleton of Spring-Data-Neo4j project in Scala. 我正在尝试在Scala中设置Spring-Data-Neo4j项目的框架。 When I run the JUnit test, and I get a MissingIndexException, I really don't have any clue why. 当我运行JUnit测试并得到MissingIndexException时,我真的不知道为什么。 I previously ran the same test successfully using the same configuration (and dependencies) in pure Java instead of scala entities/test. 我以前在纯Java中使用相同的配置(和依赖项)而不是scala实体/测试成功地运行了相同的测试。

Any help would do. 任何帮助都可以。

The (scala) persistent entity: (标量)持久性实体:

@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
}

Here is the (still java) repository interface: 这是(仍然是java)存储库接口:

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

    User findByEmail(String email);
}

The JUnit test I run: 我运行的JUnit测试:

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

An excerpt of the log: 日志摘录:

[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 {}

And the error I get: 我得到的错误是:

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

So you're likely using Cypher 2.0, and looking at your query, you don't have a MATCH--just a START and a RETURN. 因此,您可能正在使用Cypher 2.0,并且在查询中没有MATCH,只有START和RETURN。 So, first off, I'm not even sure that's legal, but you say it ran before...I've never seen that. 所以,首先,我什至不确定这是否合法,但是您说它在……之前就没发生过。 :) :)

That said, I'm pretty sure that the START clause makes use of legacy indices, and it looks like you're attempting to treat :User as a label (which is new to Neo4j 2.x). 就是说,我很确定START子句使用了旧索引,并且看起来您正在尝试将:User视为标签(这是Neo4j 2.x的新功能)。 So, when SDN creates the schema indices (with "name" and "email" as your keys), the START statement is attempting to access a legacy index for "User" which does not exist. 因此,当SDN创建模式索引(使用“名称”和“电子邮件”作为键)时,START语句尝试访问不存在的“用户”的旧索引。

Maybe try this as a query and let us know how it goes: 也许可以将其作为查询,让我们知道它的运行方式:

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

Also make sure that your parameterization is being taken care of. 另外,请确保已处理好您的参数设置。

(If I'm off on any of this, someone please feel free to correct me.) (如果我对此不满意,请有人纠正我。)

HTH HTH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM