Hibernate version: 3.0
I am running these test using the SpringFramework as the IoC container.
My Product.hbm.xml File:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.bdwd.elff.data.Product" table="product">
<!-- Map IDENTIFIER -->
<id name="id"
column="ProductID">
<generator class="native"/>
</id>
<!-- Map Additional Info Property -->
<property name="additionalInfo"
column="prodAddInfo"
type="text"/>
<!-- Map Description Info Propert -->
<property name="description"
column="prodDesc"
type="text"/>
<!-- Map Name Property -->
<property name="name"
column="prodName"
type="string"
length="150"
not-null="true"/>
<!-- Map Product Class Association -->
<many-to-one name="productClass"
column="ClassID"
class="com.bdwd.elff.data.ProductClass"/>
<!-- Map SKU Association -->
<set name="skus"
cascade="all"
inverse="true"
lazy="true">
<key column="ProductID"/>
<one-to-many class="com.bdwd.elff.data.SKU"/>
</set>
<!-- Map Features Association -->
<set name="features"
table="product_features"
lazy="false">
<key column="ProductID"/>
<element column="feature"
type="string"/>
</set>
<!-- Map Specifications Association -->
<set name="specifications"
table="product_specs"
lazy="false">
<key column="ProductID"/>
<element column="specs" type="string"/>
</set>
</class>
</hibernate-mapping>
Here is the Base Hibernate Test Case for all my DAOTests.Code:
public abstract class HibernateDAOTestBase extends TestCase {
protected SessionFactory sessionFactory ;
public void setUp() throws Exception {
super.setUp();
sessionFactory = (SessionFactory) getBean("sessionFactory");
Session s = sessionFactory.openSession();
TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(s));
}
protected Object getBean(String beanName) {
return SpringDAOTestContextFactory.getContext().getBean(beanName) ;
}
public void tearDown() throws Exception {
super.tearDown();
SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
Session s = holder.getSession();
s.flush();
TransactionSynchronizationManager.unbindResource(sessionFactory);
SessionFactoryUtils.closeSessionIfNecessary(s, sessionFactory);
}
}
Name and version of the database you are using: MySQL 4.1 InnoDBThe problem is occuring when I call this method from my DAO.
Code:
getHibernateTemplate().delete(Object);
org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
at org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:92)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:78)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:172)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:678)
at com.bdwd.elff.data.HibernateDAOTestBase.tearDown(HibernateDAOTestBase.java:28)
at com.bdwd.elff.data.TestHibernateProductDAO.tearDown(TestHibernateProductDAO.java:133)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)