代码之家  ›  专栏  ›  技术社区  ›  alexanoid

SDN5/OGM3比较java。util。Cypher查询的日期

  •  1
  • alexanoid  · 技术社区  · 8 年前

    我拥有以下实体:

    @NodeEntity
    public class Action {
    
    ...
    
        @Index(unique = false)
        private Date createDate;
    
    ...
    
    }
    

    Action 这是在前一段时间创建的。

    为此,我实现了以下存储库方法:

    @Repository
    public interface ActionRepository {
    
        @Query("MATCH (a:Action)-[:CREATED_BY]->(u:User) WHERE a.entityType = {entityType} AND a.createDate <= {minCreateDate} AND u.id = {userId} RETURN a ORDER BY a.createDate DESC LIMIT 1")
        Action findLastByEntityTypeForUser(@Param("entityType") String entityType, @Param("minCreateDate") Date minCreateDate, @Param("userId") Long userId);
    
    }
    

    我使用以下代码来测试此方法:

    decisionDao.create("Decision2", "Decision2 description", null, false, null, user1);
    
    Date minStartDate = DateUtils.addMilliseconds(new Date(), -1000 * 60);
    
    Action user1LastAction = actionRepository.findLastByEntityTypeForUser(Decision.class.getSimpleName(), minStartDate, user1.getId());
    
    assertNotNull(user1LastAction); // test fails here because of NPE
    

    但是没有这部分的密码查询 AND a.createDate <= {minCreateDate} 行动 例子

    在Neo4j级别,我的数据如下所示:

    {
       "updateDate":"2017-10-08T12:21:39.15
    3Z",
       "entityName":"General",
       "en
    tityType":"CriterionGroup",
       "entityId":1,
       "id":1,
       "type":"CREATE",
       "createDate":"2017-10-08T12:21:39.153Z"
    }
    

    我做错了什么?如何正确地将日期与SDN/OGM和Cypher进行比较?

    还有,有没有办法告诉SDN/OGM存储 java.util.Date 对象为 long 毫秒和as String ?

    1 回复  |  直到 8 年前
        1
  •  2
  •   Ira Re    8 年前

    这个 minCreateDate createDate 属性是字符串。所以,这一部分 a.createDate <= {minCreateDate} 基本上是比较 minCreateDate 和字符串属性 .

    在我的项目中,我通常将日期和时间戳尽可能长地保存在数据库和代码中。

    或者更好的是,如果日期属性对我的应用程序至关重要,我将使用“时间树模型”方法: https://graphaware.com/neo4j/2014/08/20/graphaware-neo4j-timetree.html