I have a many-to-one relationship where I would like to delete the parent object and leave the children as orphans. My test case is failing, however, and complaining about batch updates.
WARNING: SQL Error: 0, SQLState: null
Jul 10, 2006 10:37:29 AM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: failed batch
Jul 10, 2006 10:37:29 AM org.hibernate.event.def.AbstractFlushingEventListener performExecutions
SEVERE: Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
...
Here's my mapping:
Code:
<class name="Category">
<id name="id"
column="CATEGORY_ID">
<generator class="native"/>
</id>
<property name="description"/>
<property name="parentCategory"/>
<set name="pets"
inverse="true"
cascade="save-update">
<key column="category_id"/>
<one-to-many class="Pet"/>
</set>
</class>
<class name="Pet">
<id name="id"
column="pet_id">
<generator class="native"/>
</id>
<property name="productId"/>
<property name="description"/>
<property name="price"/>
<property name="quantity"/>
<many-to-one
name="category"
column="category_id"
class="Category"/>
</class>
And here's my test case:
Code:
public void testRemoveCategory() throws Exception {
// create a couple of pets
Pet pet1 = new Pet("12345", "Pet1");
Pet pet2 = new Pet("78901", "Pet2");
category.addPet(pet1);
category.addPet(pet2);
// persist the category
long id = categoryDao.store(category);
categoryDao.getHibernateTemplate().flush();
categoryDao.getHibernateTemplate().clear();
Category retrievedCategory = categoryDao.get(id);
categoryDao.remove(retrievedCategory);
categoryDao.getHibernateTemplate().flush();
categoryDao.getHibernateTemplate().clear();
retrievedCategory = categoryDao.get(id);
assertNull("retrievedCategory", retrievedCategory);
}
TIA,
Sean