JPA命名查询集

时间:2017-04-10 16:04:30

标签: linux postgresql jpa jql

我尝试使用更改2个字段的集创建命名查询。以下是我尝试过的,不起作用的。它工作正常,直到我添加了ae.endTime和setParameter。你能在一个查询中设置多个东西吗?

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

1 个答案:

答案 0 :(得分:0)

根据您对endTime字段进行映射的方式,您应该使用setParameter方法的重载变体,该方法会添加日期时间信息。例如:

updateAttempts.setParameter("now", (new Date()).getTime(), TemporalType.TIME);

更多关于Temporal Types