Results 1 to 7 of 7

Thread: How to list relationships by type in a Cypher @Query annotated method?

  1. #1
    Join Date
    Jul 2012
    Posts
    18

    Default How to list relationships by type in a Cypher @Query annotated method?

    Hi,

    Is it possible to list related items of an item filtered by relationship type like below?

    @NodeEntity
    public class POJO
    {

    ....

    private Iterable<POJO> relatedByType;

    @Query("START n1=node({self}) MATCH n1-[rel:{type}]->n2 RETURN n2")
    public Iterable<POJO> getRelatedByType(@Param("type") String type)
    {
    return relatedByType;
    }

    }

    I tried it, but it always returns empty result.

    Thank you in advance for any help!
    Last edited by hsherlock; Jul 18th, 2012 at 03:28 AM.

  2. #2
    Join Date
    May 2012
    Posts
    107

    Default

    hsherlock,

    Can you create a small example in http://console.neo4j.org, run the query, and share the results?

    Thanks,

    Lasse

  3. #3
    Join Date
    Jul 2012
    Posts
    18

    Default

    Hi Lasse,

    Unfortunately I don't think it could be demonstrated in the Neo4j console because I didn't found any way to pass query-external parameters in format {...}. Actually, the query is ok, because when I execute it with exact type name instead of [:{type}] it returns correct results.

    I tested again and the following method always returns empty (Iterable) result.

    @Query("START n1=node({self}) MATCH n1-[rel:{type}]->n2 RETURN n2")
    public Iterable<POJO> getRelatedByType(@Param("type") String type)
    {
    return relatedByType;
    }

    p.s. In the meantime I think I've found another related problem http://forum.springsource.org/showth...e-like-type-gt

  4. #4
    Join Date
    May 2012
    Posts
    107

    Default

    hsherlock,

    Parameterised relationship types are not supported: http://docs.neo4j.org/chunked/milest...arameters.html

    Regards,

    Lasse

  5. #5
    Join Date
    Jul 2012
    Posts
    18

    Default

    Ok, now I see - it is not allowed to insert parameters like MATCH ....[rel:{NOT_ALLOWED}]...

    Tried to slightly modify the query according the example from "Good Relationships" book
    .... WHERE rel.type='some_type'...
    Failed both in cypher query invoked from Java code and in http://console.neo4j.org/
    It looks that .type property of a Relationship cannot be accessed this way.

    While hacking with http://console.neo4j.org/ noted "type(rel)" and the query finally works both from java and in console when
    .... WHERE type(rel)='someType'...
    .... WHERE type(rel)={relType} ...

    Now returning back to the @Query annotated method which now became:
    @Query(value="START n=node({self}) MATCH n-[rel]->relN WHERE type(rel)={relType} RETURN relN")
    public Iterable<POJO> getRelationshipsByType(@Param("relType") String type)
    {
    return relationshipsByType;
    }
    Again - empty result!

  6. #6
    Join Date
    May 2012
    Posts
    107

    Default

    hsherlock,

    I am as mystified as you are. One thing to try though quickly, I think you might have to name the query parameter the same as the method parameter - i.e. ignoring the @Param bit, if the method parameter name is 'foo' you can refer to {foo} in the query.

    Let me know the outcome.

    Lasse

  7. #7
    Join Date
    Jul 2012
    Posts
    18

    Default

    Hi Lasse,

    Tried as you suggested and renamed the method argument as below
    public Iterable<POJO> getRelationshipsByType(@Param("relType") String relType)
    No success here - same result - empty result returned.

    In the meantime I've noted that the query is not executed at all and no exception is produced even if I put totally invalid query there and it looks as the core problem now. As it does not look like a paramer handling issue anymore I posted this as another thread http://forum.springsource.org/showth...s-not-invoked-!
    Last edited by hsherlock; Jul 20th, 2012 at 03:58 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •