本文介绍了与Spring Data neo4j比较日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java.util.Date 属性中查询关系时,应该使用什么语法?我尝试只使用一个查询(这只是一个例子来显示我想要做的,所以请不要注意变量名称):

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);

但它会引发以下错误:

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.

我正在使用spring-data-neo4j版本2.0.1.RELEASE

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

推荐答案

所以date属性的long值存储在图形中的一个字符串(在较新版本的SDN中,你可以定义一个@Graph属性(targetType = long.class)在日期字段。

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.

因此,如果将参数值传递为 String.valueOf(longValue )

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

这篇关于与Spring Data neo4j比较日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 20:49
查看更多