2013-06-12 21 views
-2

例如,在SQL查询,它将:如何通过EntityManager删除表中的一些行?

delete from Mails where name='....' 

如何通过EntityManager的执行呢?

+0

entityManager.remove(name) – MTT

+0

它不工作。我试过了: EntityManager em = Server.emf.createEntityManager(); em.getTransaction()。begin(); 邮件邮件=新邮件(); mail.setName(username); em.remove(mail); em.getTransaction()。commit(); em.close(); – rustock

回答

1

你可以用命名查询来做到这一点。 Here's an example

query = em.createNamedQuery("SELECT c FROM Country c"); 
List results = query.getResultList(); 

而不是使用选择,使用删除的方式,你想要的。请注意,这不使用SQL,但JPQL

+0

em.createQuery()。executeQuery解决了我的问题。谢谢。 – rustock