2

I have two entities: User and Connection, along with two appropriate repositories. Both entities has @GraphId id field. Connection entity has User user field.

In ConnectionRepository interface I added following method:

List<Connection> findByUserId(long userId)

But it doesn't work. It generates incorrect cypher query. I think it incorrect, because it contains clause like this:

WHERE user.id = 15

which is not working, because id is not a property. It must be:

WHERE id(user) = 15

Is this a bug? In any case, how can I get it to work?

Christophe Willemsen
  • 19,399
  • 2
  • 29
  • 36
Victor Dombrovsky
  • 2,955
  • 3
  • 21
  • 33

1 Answers1

3

The derived query translates to the property id of the user defined on the Connection. It is quite possible that node entities contain a user managed id property as well and it would be incorrect to assume that id is always the node id.

In this case, you might want to use a @Query instead.

@Query("MATCH (user:label) WHERE ID(user)={0} return user")
List<Connection> findByUserId(long userId)
Luanne
  • 19,145
  • 1
  • 39
  • 51
  • Thanks for explanation! Currently I already used this workaround. But I thought, there are special means to do that. – Victor Dombrovsky Aug 26 '15 at 05:45
  • 1
    There's the repo.findOne that takes a node ID, but of course, that will just give you the single node that matches this id. Not useful for querying with other conditions involved – Luanne Aug 26 '15 at 05:55
  • Method repo.findOne is not suitable not only because it is not useful for querying with other conditions, but mainly because it searches one entity by its id instead of search list of entities by id of related entity (in my case, user has relation to connection). – Victor Dombrovsky Aug 26 '15 at 11:52