Question

I'm trying to setup a skeleton of Spring-Data-Neo4j project in Scala. When I run the JUnit test, and I get a MissingIndexException, I really don't have any clue why. I previously ran the same test successfully using the same configuration (and dependencies) in pure Java instead of scala entities/test.

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:

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:

@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
Was it helpful?

Solution

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. 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). 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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top