gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 08:48:30 30 4
gpt4 key购买 nike

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

并且我想删除这个我的列表...
我该怎么做?

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

非常感谢!!

最佳答案

尝试一个一个地删除元素:

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

关于java - 如何从 org.hibernate.collection.PersistentBag 中删除数据? | hibernate (Jpa),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23920323/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com