-1

这是方法:

public void deleteVotesByReplyID(long replyId) {
        EntityManager em = getEntityManager();
        try {
           int re = em.createQuery("delete object(o) 
                                    from Vote as o 
                                    where o.memberReply.id = '"+replyId+"'"
                                  ).executeUpdate();       
        } finally {
            em.close();
        }
    }

上面的查询有什么问题?(使用 jpa 1.0)

4

2 回答 2

1

可能是因为删除查询开始

DELETE FROM entity_name [[AS] identification_variable] [WHERE <filter>]
于 2012-07-13T13:06:16.087 回答
0

您的查询可以写成

"DELETE from Vote o where o.memberReply.id = 'someId'"

此外,DELETE 查询只能在活动事务中执行。你会想要

em.getTransaction().begin();
query.executeUpdate();
em.getTransaction().commit();

并且还要

catch (Exception e) {em.getTransaction().rollback();}
于 2013-08-12T01:48:21.490 回答