Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.0.5
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="org.hibernate.auction.model">
<!--
Mapping file for the CategorizedItem class of CaveatEmptor.
This is really a very special mapping. The CategorizedItem class
represents an association table. The ER model for this is really
a many-to-many association, but instead of two entities and two
collections, we mapped this as two one-to-many associations between
three entities. One of the motivation for this are the additional
attributes on the association table (not only two FKs): username
and creation date.
This class is the entity in the middle, between Category and Item.
You can see that it has references to both. The trick is the usage
of update="false" insert="false" on the <many-to-one> mapping
elements. The foreign/primary key columns of the association table
is therefore managed by the <key-property> mappings in the composite
key.
Note that the composite key is encapsulated in an inner class, which
simplifies the implementation of equals/hashCode. We recommend to
always use a separate composite key class.
@author Christian Bauer <christian@hibernate.org>
-->
<class name="CategorizedItem"
table="CATEGORIZED_ITEM"
lazy="true">
<composite-id name="id" class="CategorizedItem$Id"
access="org.hibernate.auction.persistence.DirectSetAccessor"
unsaved-value="any">
<key-property name="categoryId"
access="field"
column="CATEGORY_ID"
length="16"/>
<key-property name="itemId"
access="field"
column="ITEM_ID"
length="16"/>
</composite-id>
<property name="dateAdded"
column="DATE_ADDED"
type="java.util.Date"
update="false"
not-null="true"
access="org.hibernate.auction.persistence.DirectSetAccessor"/>
<property name="username"
column="USERNAME"
type="string"
update="false"
not-null="true"
access="org.hibernate.auction.persistence.DirectSetAccessor"/>
<many-to-one name="category"
insert="false"
update="false"
not-null="true"
access="org.hibernate.auction.persistence.DirectSetAccessor"
column="CATEGORY_ID"/>
<many-to-one name="item"
insert="false"
update="false"
not-null="true"
access="org.hibernate.auction.persistence.DirectSetAccessor"
column="ITEM_ID"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:558)
[junit] [sabah] ERROR [main] AbstractFlushingEventListener.performExecutions(277) | Could not synchronize datab
ase state with session
[junit] org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row coun
t: 0 expected: 1
[junit] at org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:92)
[junit] at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:78)
[junit] at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
[junit] at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
[junit] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
[junit] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:137)
[junit] at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener
.java:274)
[junit] at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
[junit] at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
[junit] at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:249)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:313)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:612)
[junit] at org.sabah.dao.hibernate.ItemDAOHibernate.saveItem(ItemDAOHibernate.java:2
6)
[junit] at org.sabah.dao.ItemDAOTest.testAddItem(ItemDAOTest.java:175)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[junit] at java.lang.reflect.Method.invoke(Method.java:585)
[junit] at junit.framework.TestCase.runTest(TestCase.java:154)
[junit] at junit.framework.TestCase.runBare(TestCase.java:127)
[junit] at junit.framework.TestResult$1.protect(TestResult.java:106)
[junit] at junit.framework.TestResult.runProtected(TestResult.java:124)
[junit] at junit.framework.TestResult.run(TestResult.java:109)
[junit] at junit.framework.TestCase.run(TestCase.java:118)
[junit] at junit.framework.TestSuite.runTest(TestSuite.java:208)
[junit] at junit.framework.TestSuite.run(TestSuite.java:203)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:289)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:656)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:558)
[junit] Testsuite: com.stufftolet.dao.PostingDAOTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 1.311 sec
[junit] Testcase: testAddItem(org.sabah.dao.ItemDAOTest): Caused an ERROR
[junit] Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1; nested exception
is org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expe
cted: 1
[junit] org.springframework.orm.hibernate3.HibernateSystemException: Batch update returned unexpected row count from
update: 0 actual row count: 0 expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned
unexpected row count from update: 0 actual row count: 0 expected: 1
[junit] org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row coun
t: 0 expected: 1
[junit] at org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:92)
[junit] at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:78)
[junit] at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
[junit] at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
[junit] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
[junit] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:137)
[junit] at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener
.java:274)
[junit] at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
[junit] at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
[junit] at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:249)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:313)
[junit] at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:612)
[junit] at org.sabah.dao.hibernate.ItemDAOHibernate.saveItem(ItemDAOHibernate.java:2
6)
[junit] at org.sabah.dao.ItemDAOTest.testAddItem(ItemDAOTest.java:175)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
Name and version of the database you are using:Mysql 4.1
Hi guys,
I have a question for the the following code in TestCaseWithData class which is inside the caveatemptor-0.9.5.zip :
itemDAO.makePersistent(auctionOne);
new CategorizedItem(u1.getUsername(), carsLuxury, auctionOne);
I just don't understand why do u need to 'new' a categorizedItem even after saving (makePersistent) the auction one.
I tried it out and get the above error. I know that it's bcoz Item has not save yet then CategorizedItem.ITEM_ID tried to reference it then get this error. Appreciate someone can give a little help here, Thanks !
regards,
prettyhandling