-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: StaleStateException HELP!!
PostPosted: Thu Jun 02, 2005 3:36 pm 
Newbie

Joined: Thu Jun 02, 2005 3:25 pm
Posts: 7
Location: Traverse City, MI
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 InnoDB

The 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)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 02, 2005 5:23 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
You'll get that if you try to delete an object that's not persistent. How did you get the object you are deleting?


Top
 Profile  
 
 Post subject: It was JUnit
PostPosted: Thu Jun 02, 2005 9:05 pm 
Newbie

Joined: Thu Jun 02, 2005 3:25 pm
Posts: 7
Location: Traverse City, MI
It was a problem with JUnits tearDown() method. I had the dao.delete() call in the tearDown() method and it was getting called for each testXXX() method.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.