I have a class Assignment, whose id is a long with unsaved-value of 0. I explicitly set the id to 0 when a new class is created. However, when I saveOrUpdate a new Assignment, is tries to update a row, and then returns a "Batch update row count wrong: 0" error.
Mapping:
Code:
<hibernate-mapping package="com.martin.model" >
<class name="Assignment" table="assignments">
<id name="id" column="id" type="long" unsaved-value="0">
<generator class="sequence">
<param name="sequence">assignments_id_seq</param>
</generator>
</id>
<property name="sequenceNumber" type="int" column="sequence_number" not-null="false" unique="false" />
<property name="minimumScore" type="java.lang.Integer" column="minimum_score" not-null="false" unique="false" />
<property name="quickStudy" type="boolean" column="quick_study" not-null="true" unique="false" />
<property name="master" type="boolean" column="master" not-null="true" unique="false" />
<property name="test" type="boolean" column="test" not-null="true" unique="false" />
<many-to-one name="course" class="Course" column="course_id" />
<set name="units" table="assignment_unit_mapping" lazy="true">
<key column="assignment_id"/>
<many-to-many column="unit_id" class="Unit"/>
</set>
<!--inverse="true" means that Homework is responsible for the relation-->
<set name="homework" inverse="true" lazy="true">
<key column="assignment_id"/>
<one-to-many class="Homework"/>
</set>
</class>
Save Code:
Code:
assignment.setUnits(unitSet);
assignment.setQuickStudy( quickStudy );
assignment.setMaster(master);
assignment.setTest(test);
course = (Course)get("course");
assignment.setCourse(course);
log.info("- saving assignment: "+assignment);
assignmentDAO.saveOrUpdate(assignment);
log.info("- Assignment saved.");
I am using an interceptor with Webwork, which closes and flushes the session after the view is rendered, so that code is not here.
Any help? I have searched the forums and documentation, and am still confused as to why the unsaved-value=0 is not respected. If I print out the id of the new Assignment before saving it, it is 0, so I know it should get inserted, not updated.
The Error:
Code:
Hibernate: update assignments set sequence_number=?, minimum_score=?, quick_study=?, master=?, test=?, course_id=? where id=?
Feb 12, 2004 5:48:45 PM net.sf.hibernate.impl.SessionImpl execute
SEVERE: Could not synchronize database state with session
net.sf.hibernate.HibernateException: Batch update row count wrong: 0