I have two pojos, both of them have a collection bids.
What I want is to remove an element from this collection so I am using the following code:
Session session = HibernateUtil.getCurrentSession();
Thing thing = session.load(Thing.class, thingId);
Item item= session.load(Item.class, itemId);
thing.getBids().remove(bid);
item.getBids().remove(bid);
session.save(thing);
session.save(item);
session.close();
In my mapping files (Item.hbm.xml, Thing.hbm.xml) I have in the set
tag of the collections bids the property cascade="all-delete-orphan".
The above code works however if I try to delete 20-25 bids I get the following exception:
StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)
Any suggestions?
|