2
我想創建一個具有更改2個字段的集合的名稱查詢。以下是我嘗試過的,這不起作用。它工作正常,直到我添加ae.endTime和setParameter。你不能在一個查詢中設置多個東西嗎?JPA命名查詢集
@NamedQuery(name = AttEnt.JQL.MARK_INCOMPLETE,
query = "UPDATE AttEnt ae"
+ " SET ae.result ="
+ " Result.INCOMPLETE,"
+ " ae.endTime = :now"
+ " WHERE ae.result IS NULL")
下面是我打電話給查詢的地方。
final EntityManager em = emf.createEntityManager();
// Mark things with no result as incomplete and endTime to current time
em.getTransaction().begin();
final Query upAtt = em.createNamedQuery(
AttEnt.JQL.MARK_INCOMPLETE);
updateAttempts.setParameter("now", (new Date()).getTime());
upAtt.executeUpdate();
em.getTransaction().commit();
我不得不刪除getTime(),因爲那是返回一個int並且與TemporalType不匹配。我結束了使用以下,它做我需要的。 updateAttempts.setParameter(「now」,new Date(),TemporalType.TIMESTAMP); – ralyn