Results 1 to 6 of 6

Thread: [Neo4J] Simple cypher question

  1. #1

    Default [Neo4J] Simple cypher question

    Hey everyone!

    Assume there are two node entities:

    Code:
    public class Account extends BaseEntity
    {
        ...
        @Fetch
        @RelatedTo(type = "HAS_ROLE")
        private Set<Role> roles = Sets.newHashSet();
        ...
    }
    
    public class Role extends BaseEntity
    {
        ...
    }
    In my repository, I have a Query that gets all Accounts by a given Role:

    Code:
    public interface AccountRepository extends GraphRepository<Account>
    {
        @Query("START account=node:Account(0) MATCH account-[:HAS_ROLE]->({0}) return account")
        Iterable<Account> findByRole(Role role);
    But this query doesn't work, when I use this method in my test case I get the following error:

    Code:
    org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement START account=node:Account(0) MATCH account-[:HAS_ROLE]->({0}) return account; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement START account=node:Account(0) MATCH account-[:HAS_ROLE]->({0}) return account; nested exception is expected string
    As it seems, there is something wrong with my query, but I don't know what, and could't figure it out yet...
    Could anyone provide some help??
    THANKS!

  2. #2
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    this is no valid index query: node:Account(0)
    if you want to find all accounts use: node:Account("key:*") where key has to be an valid, indexed key of account, or
    node:`__types__`(classname="com.example.Account")

    Usually what you would rather do is to lookup the role from an index (or pass it in as you already did) and just navigate from there.

    i.e.

    Code:
    public interface AccountRepository extends GraphRepository<Account>
    {
        @Query("START role=node({0}) MATCH account-[:HAS_ROLE]->role return account")
        Iterable<Account> findByRole(Role role);
    }
    Usually SDN can figure that out on its own (by just using a derived finder):

    Code:
    public interface AccountRepository extends GraphRepository<Account>
    {
        Iterable<Account> findByRoles(Role role);
    }

  3. #3

    Default

    Hey Michael!
    Many thanks, the lookup from the role index works perfect.
    Using a derived query didn't work, it always ended in:

    Code:
    java.lang.IllegalStateException: Error roles SIMPLE_PROPERTY points neither to a primitive nor a entity property of class de.bht.streetartatlas.domain.auth.Account unmanaged @NodeEntity Annotations: [interface org.springframework.data.neo4j.annotation.NodeEntity]
    A lot of new things to learn...

  4. #4
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    Thanks Markus,

    Could you perhaps create a small test/sample project that exhibits the problem in a test?

    That would help me to easily pinpoint and fix it.

    Thanks

    Michael

  5. #5

    Default

    Hey Michael,

    here's my project...
    It's simple, so far...

    The problem:
    This works fine, thanks to you:

    Code:
    @Query("START role=node({0}) MATCH account-[:HAS_ROLE]->role return account")
    Iterable<Account> findByRoles(Role role);
    Without the query string, the error occurs:

    Code:
    Error roles SIMPLE_PROPERTY points neither to a primitive nor a entity property of class de.bht.streetartatlas.domain.auth.Account unmanaged @NodeEntity Annotations: [interface org.springframework.data.neo4j.annotation.NodeEntity]
    P.S.: The relevant one is AccountServiceTest...
    Attached Files Attached Files

  6. #6
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    Thanks for pointing it out, will fix it, see

    https://jira.springsource.org/browse/DATAGRAPH-308

Posting Permissions

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