一尘不染

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

hibernate

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????
   }
}

非常感谢你!!


阅读 414

收藏
2020-06-20

共1个答案

一尘不染

尝试一一删除元素:

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

_____
解决方案(对我有用,感谢“ Genzotto”):

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