2

The List<String> Mylist is org.hibernate.collection.PersistentBag...

and i want to delete this Mylist...
How i can do it??

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

Thank you very much!!

user3515151
  • 97
  • 2
  • 10
  • What exactly do you want to do? You can't delete a list. You can clear it, i.e. remove everything it contains, using the standard `clear()` method. – JB Nizet May 28 '14 at 20:41
  • http://stackoverflow.com/questions/23914149/how-delete-data-from-collectiontable-hibernate-jpa as you can see this Mylist is ArrayList in entity, so i want to delete this list data from the CollectionTable... – user3515151 May 28 '14 at 21:22

1 Answers1

0

Try deleting elements one by one:

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

_______________________
The Solution (Work to me, thank to "Genzotto"):

List<String> Mylist = a.getMyList();
listStirng.clear();
em.getTransaction().begin();
     for (String str : Mylist) {
         em.merge(str);
     }
em.getTransaction().commit();
user3515151
  • 97
  • 2
  • 10
Genzotto
  • 1,954
  • 6
  • 26
  • 45
  • i get an error: org.hibernate.MappingException: Unknown entity: java.lang.String. @Genzotto – user3515151 May 29 '14 at 09:39
  • You should check your mappings and make sure they are correct. You can also clear the list (using clear() method), and then updating your A element with em.merge(object_of_A_class) – Genzotto May 29 '14 at 09:46
  • gooooooddd!!!! i clear the list (using clear() method), and then updating your A element with em.merge(object_of_A_class) and it's work!!! thank!!!! – user3515151 May 29 '14 at 09:54