3

When querying for relationships on a java.util.Date property, what syntax should I use? I tried just using a query like (this is just an example to show what I'm trying to do, so please don't pay attention to variable names there):

@Query("start n1=node({0}) match n1-[r:TYPE]->n2 where r.dateCreated>={1} return r")
Page<Relationship> findAll(Node node, long date, Pageable pager);

But it throws the following error:

Caused by: Don't know how to compare that. Left: 1339845862883; Right: 1339827156836
at org.neo4j.cypher.internal.Comparer$class.compareValuesOfDifferentTypes(Comparer.scala:45)
at org.neo4j.cypher.internal.Comparer$class.compare(Comparer.scala:67)
at org.neo4j.cypher.commands.ComparablePredicate.compare(ComparablePredicate.scala:30)
at org.neo4j.cypher.commands.ComparablePredicate.isMatch(ComparablePredicate.scala:41)
at org.neo4j.cypher.internal.pipes.matching.PatternMatcher$$anonfun$isMatchSoFar$1.apply(PatternMatcher.scala:148)
at org.neo4j.cypher.internal.pipes.matching.PatternMatcher$$anonfun$isMatchSoFar$1.apply(PatternMatcher.scala:148)

I also tried by passing a Date but it just throws the same error but trying to compare a Long and a Date.

I am using spring-data-neo4j version 2.0.1.RELEASE

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Guillaume
  • 2,912
  • 3
  • 35
  • 59

1 Answers1

2

So the date property's long value is stored as a string in the graph (in newer versions of SDN you can define a @GraphProperty(targetType=long.class) on date fields.

So comparison will work if you pass in the parameter value as String.valueOf(longValue)

Michael Hunger
  • 41,339
  • 3
  • 57
  • 80
  • yeah I came to the same idea to change to a string instead of a long, why choosing to store it as a string instead of a long though? – Guillaume Jul 07 '12 at 17:08
  • and also, if it stores it as a String, passing a parameter as Date should automatically convert it to a String to avoid throwing the error, shouldn't it?? – Guillaume Jul 08 '12 at 13:37
  • Right, that's true. But as we don't know (in SDN) what you write in your custom query it is hard to do any conversions. That is different in the derived finder methods though. – Michael Hunger Aug 08 '12 at 06:37