2
votes

Assume there are two node entities:

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 should get all Accounts by a given Role:

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:

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?

3
Please specify the version of Neo4j used, it IS important.raina77ow
I'm using neo4j 1.8.M07, spring-data-neo4j 2.1.0.BUILD-SNAPSHOTMarkus Lamm
Please accept an answer or answer (and accept) your own. It looks like you've got a solution ("I changed it to ... and everything is fine") and it would be good to get this question closed!cod3monk3y

3 Answers

0
votes

Markus,

You should migrate to Neo4j 1.8 GA and SDN 2.1.0 RELEASE.

Also, what does your BaseEntity and Role classes look like?

Regards,

Lasse

0
votes

Rewrite your query like this. You already know the Role so use it as a STARTing point.

@Query("START role=node({0}) MATCH account-[:HAS_ROLE]->role return account")
Iterable<Account> findByRole(Role role);
0
votes

How about using this query?

START account=node(*) MATCH (account)-[r:HAS_ROLE]->() return account

it will be return all account has 'HAS_ROLE'