spring-projects / spring-data-neo4j

Provide support to increase developer productivity in Java when using Neo4j. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
http://spring.io/projects/spring-data-neo4j
Apache License 2.0
825 stars 619 forks source link

Nested Derived Finder Query - incorrect query generated by OGM [DATAGRAPH-681] #1216

Closed spring-projects-issues closed 6 years ago

spring-projects-issues commented 9 years ago

Greg Guydo opened DATAGRAPH-681 and commented

Given the following node:

public class Entity {
   private String name;
   private Entity parent;
   //getters and setters and graph id
}

and the following repository method

public interface EntityRepository extends GraphRepository<Entity> {

   public Set<Entity> findByParent_Name(String parentName);

}

the OGM framework VariableDepthQuery generates the following query:

MATCH (n:`Entity`) where m0.`name` = { `parent_name` } MATCH (n)-[:`PARENT`]->(m0) WITH n MATCH p=(n)-[*0..1]-(m) RETURN collect(distinct p), ID(n)

which throws an error "m0 not defined"


Affects: 4.0 M1, 4.0 RC1

1 votes, 3 watchers

spring-projects-issues commented 9 years ago

Luanne Misquitta commented

Hi Greg, is there a reason why there's an underscore in findByParent_Name (instead of findByParentName)?

spring-projects-issues commented 9 years ago

Greg Guydo commented

I pulled this format from the docs - and it was necessary in my case since I do have a field parentName on entity that is transient.

http://docs.spring.io/spring-data/data-commons/docs/1.8.0.RELEASE/reference/html/repositories.html Section 1.2.2 Heading Property Expressions

spring-projects-issues commented 9 years ago

Luanne Misquitta commented

Unfortunately that is not supported yet. Leaving this issue open

spring-projects-issues commented 8 years ago

Mark Paluch commented

Similar issue for me. I'm trying to query a property name of related entities.

Code

@NodeEntity
public class Person {

    @GraphId
    private Long id;

    private String name;

    @Relationship(type="TEAMMATE")
    public Set<Person> teammates;

    // ...
}

public interface PersonRepository extends GraphRepository<Person> {

    List<Person> findByTeammatesName(String name);
}

Exception

Caused by: org.neo4j.kernel.impl.query.QueryExecutionKernelException: m0 not defined (line 1, column 26 (offset: 25))
"MATCH (n:`Person`) WHERE m0.`name` = { `teammates_name` } MATCH (n)-[:`TEAMMATE`]-(m0) WITH n MATCH p=(n)-[*0..1]-(m) RETURN p, ID(n)"