Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare dates with Spring Data neo4j

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

like image 619
Guillaume Avatar asked Jan 01 '26 05:01

Guillaume


1 Answers

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)

like image 137
Michael Hunger Avatar answered Jan 03 '26 14:01

Michael Hunger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!