我有一个Java项目,其中包含一个具有LocalDateTime的实体。我想通过SQL提取记录,其中LocalDateTime介于2个其他LocalDateTime之间。
ENTITY
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(nullable = false)
private long id;
@Basic(optional = false)
@Column(nullable = false)
private long assignmentId;
@Basic(optional = false)
@Column(nullable = false)
private LocalDateTime startDateTime;
@Basic(optional = false)
@Column(nullable = false)
private LocalDateTime endDateTime;
JAVA
//Sub assignments
public List<Subassignment> findAllSubassignmentsForAssignmentBetweenDates(long id, LocalDateTime startDateTime, LocalDateTime endDateTime) {
return getEntityManager().createNamedQuery("ResourceVO.findByAssignmentIdAndDates", Subassignment.class)
.setParameter("id", id)
.setParameter("sdt", startDateTime)
.setParameter("edt", endDateTime)
.getResultList();
}
QUERY
<named-query name='ResourceVO.findByAssignmentIdAndDates'>
<query>
SELECT c FROM Subassignment AS c
WHERE (c.assignmentId IN (SELECT b.id FROM Assignment b WHERE b.resource.id = :id))
AND (c.startDateTime BETWEEN :sdt AND :edt)
</query>
</named-query>
我总是收到“内部服务器错误”。有任何提示或建议吗?
P.S。没有LocalDateTime参数,查询工作正常。
由于
Matthijs
答案 0 :(得分:0)
我将LocalDateTime更改为long