I am trying to delete data from a History table and also want to remove the data from the historyList .
If I use the below code i get ConcurrentModificationException .
If I use iterator inside foreach I get IllegalStateException .
I have a History class as an Entity with hid as @Id and @GeneratedValue(strategy = GenerationType.IDENTITY)
if i remove the historyList.remove(d) from code i get org.hibernate.StaleStateException:
Is there any way to overcome this problem . Please help if possible.
Thanks
for (History d : historyList) {
Transaction txn = session.beginTransaction();
session.delete(d);
historyList.remove(d);
System.out.println("Deleted Successfully");
txn.commit();
}