我有以下实体:
@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
但是如果没有这部分 Cypher 查询AND a.createDate <= {minCreateDate}
,我可以成功找到Action
实例。
在 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
毫秒和String
?