【问题标题】:Compare dates with Spring Data neo4j将日期与 Spring Data neo4j 进行比较
【发布时间】:2012-06-22 09:42:03
【问题描述】:

查询java.util.Date 属性上的关系时,我应该使用什么语法?我尝试使用类似的查询(这只是一个显示我正在尝试做的事情的示例,所以请不要注意那里的变量名称):

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

我也尝试通过传递一个日期,但它只是抛出相同的错误,但试图比较一个长和一个日期。

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

【问题讨论】:

    标签: date neo4j cypher spring-data-neo4j


    【解决方案1】:

    因此,日期属性的 long 值作为字符串存储在图表中(在较新版本的 SDN 中,您可以在日期字段上定义 @GraphProperty(targetType=long.class)。

    因此,如果您将参数值作为String.valueOf(longValue) 传递,则比较将起作用

    【讨论】:

    • 是的,我也有同样的想法,将其改为字符串而不是长字符串,但为什么选择将其存储为字符串而不是长字符串?
    • 而且,如果将其存储为字符串,将参数作为 Date 传递应该会自动将其转换为字符串以避免抛出错误,不是吗??
    • 对,没错。但由于我们不知道(在 SDN 中)您在自定义查询中写了什么,因此很难进行任何转换。但是,派生的 finder 方法是不同的。
    猜你喜欢
    • 1970-01-01
    • 2017-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-16
    相关资源
    最近更新 更多