如何从org.hibernate.collection.PersistentBag中删除数据? | Hibernate(Jpa)

时间:2014-05-28 19:31:22

标签: java hibernate jpa persistence

List<String> Mylistorg.hibernate.collection.PersistentBag ...

我想删除此Mylist ...
我怎么做?

QriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery<A_entity> criteriaQuery = criteriaBuilder.createQuery(A_entity.class);
criteriaQuery.from(A_entity.class);
Query query = em.createQuery(criteriaQuery);
List<A_entity> queryList = query.getResultList();
for (A_entity a:queryList)
{
   if(....)
   {
     List<String> Mylist = a.func();
     ???How delete Mylist????
   }
}

非常感谢!!

1 个答案:

答案 0 :(得分:0)

尝试逐个删除元素:

List<String> Mylist = a.getMyList();
em.getTransaction().begin();
for (String element:Mylist){
    em.remove(element);
}
em.getTransaction().commit();

<强> _______________________
解决方案(对我有用,感谢&#34; Genzotto&#34;):

List<String> Mylist = a.getMyList();
listStirng.clear();
em.getTransaction().begin();
     for (String str : Mylist) {
         em.merge(str);
     }
em.getTransaction().commit();