I have something like this:
Code:
class A {
private List<B> lotOfBs=new ArrayList;
public void deleteOneB(B b){
lotOfBs.remove(b);
this.save();
}
public void save(){
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
session.saveOrUpdate(this);
session.getTransaction().commit();
}
//oid declaration, getter and setter
}
this is more or less the mapping
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class table="a" lazy="false" name="A">
<id column="a_id" name="oid">
<generator class="native"/>
</id>
<list lazy="false" cascade="all,delete-orphan" name="lotOfBs">
<key column="a_id"/>
<index column="position"/>
<one-to-many class="B"/>
</list>
</class>
</hibernate-mapping>
The problem is that B is not deleted from the DB. I don't know why the cascade doesn't delete it.
I also tried to put "session.delete(b)", but when I load A the collection has null in B's position.
i also tried to delete B and then update A, but the following exception was thrown
org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
due to I was trying to delete B twice.
Any clue?
Thanks
Neuquino