Announcement Announcement Module
Collapse
No announcement yet.
[Neo4J] Simple cypher question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [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
    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);
    }

    Comment


    • #3
      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...

      Comment


      • #4
        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

        Comment


        • #5
          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...

          Comment


          • #6
            Thanks for pointing it out, will fix it, see

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

            Comment

            Working...
            X