I'm, trying to implement cascade saving in the posted code below.
I'm trying to reproduce the examples provided in section 16.3 in Hibernate reference documentation (2.1.7).
I get
net.sf.hibernate.HibernateException: Batch update row count wrong: 0
while trying...
Hibernate version:
2.1.7c
Mapping documents:
<class name="Parent" table="Parent">
<id name="id" column="id">
<generator class="native" />
</id>
<property name="name" />
<set name="children" inverse="true" cascade="all">
<key column="parent_id" />
<one-to-many class="Child" />
</set>
</class>
<class name="Child" table="Child">
<id name="id" column="id">
<generator class="native" />
</id>
<many-to-one name="parent" class="Parent" column="parent_id" not-null="true"/>
<property name="name" />
</class>
Code between sessionFactory.openSession() and session.close():
Code:
Transaction tx = session.beginTransaction();
long start = 0;
long end = 0;
long result = 0;
try
{
List list = null;
start = System.currentTimeMillis();
Parent parent = (Parent)session.load(Parent.class, new Long(1) );
Child child = new Child("jme1");
parent.addChild(child);
session.flush();
tx.commit();
}
catch(Exception e)
{
tx.rollback();
System.out.println(e);
e.printStackTrace();
}
Full stack trace of any exception that occurs:
net.sf.hibernate.HibernateException: Batch update row count wrong: 0
Name and version of the database you are using:
Mysql 4.1.12 Win
The generated SQL (show_sql=true):
Hibernate: select parent0_.id as id0_, parent0_.name as name0_ from Parent parent0_ where parent0_.id=?
- PREPARE created: Tue Aug 16 13:21:20 EEST 2005 duration: 15 connection: 0 statement: 3 resultset: -1 message: select parent0_.id as id0_, parent0_.name as name0_ from Parent parent0_ where parent0_.id=?
- EXECUTE created: Tue Aug 16 13:21:20 EEST 2005 duration: 0 connection: 0 statement: 3 resultset: -1
Hibernate: select children0_.parent_id as parent_id__, children0_.id as id__, children0_.id as id0_, children0_.parent_id as parent_id0_, children0_.name as name0_ from Child children0_ where children0_.parent_id=?
- PREPARE created: Tue Aug 16 13:21:20 EEST 2005 duration: 0 connection: 0 statement: 4 resultset: -1 message: select children0_.parent_id as parent_id__, children0_.id as id__, children0_.id as id0_, children0_.parent_id as parent_id0_, children0_.name as name0_ from Child children0_ where children0_.parent_id=?
- EXECUTE created: Tue Aug 16 13:21:20 EEST 2005 duration: 0 connection: 0 statement: 4 resultset: -1
Hibernate: update Child set parent_id=?, name=? where id=?
- PREPARE created: Tue Aug 16 13:21:20 EEST 2005 duration: 0 connection: 0 statement: 5 resultset: -1 message: update Child set parent_id=?, name=? where id=?
- EXECUTE created: Tue Aug 16 13:21:20 EEST 2005 duration: 0 connection: 0 statement: 5 resultset: -1
- Could not synchronize database state with session
- QUERY created: Tue Aug 16 13:21:20 EEST 2005 duration: 0 connection: 0 statement: 999 resultset: 0 message: rollback
- FETCH created: Tue Aug 16 13:21:20 EEST 2005 duration: 0 connection: 0 statement: 999 resultset: 0
Debug level Hibernate log excerpt: