[英]Neo4j: MissingIndexException on a Node
我正在嘗試在Scala中設置Spring-Data-Neo4j項目的框架。 當我運行JUnit測試並得到MissingIndexException時,我真的不知道為什么。 我以前在純Java中使用相同的配置(和依賴項)而不是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
因此,您可能正在使用Cypher 2.0,並且在查詢中沒有MATCH,只有START和RETURN。 所以,首先,我什至不確定這是否合法,但是您說它在……之前就沒發生過。 :)
就是說,我很確定START子句使用了舊索引,並且看起來您正在嘗試將:User視為標簽(這是Neo4j 2.x的新功能)。 因此,當SDN創建模式索引(使用“名稱”和“電子郵件”作為鍵)時,START語句嘗試訪問不存在的“用戶”的舊索引。
也許可以將其作為查詢,讓我們知道它的運行方式:
MATCH (n:User {email: <whatever>}) RETURN count(*);
另外,請確保已處理好您的參數設置。
(如果我對此不滿意,請有人糾正我。)
HTH
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.