-->
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.  [ 4 posts ] 
Author Message
 Post subject: 16.3. Cascading lifecycle
PostPosted: Tue Aug 16, 2005 6:26 am 
Newbie

Joined: Mon Jun 06, 2005 8:21 am
Posts: 13
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:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 2:14 pm 
Regular
Regular

Joined: Wed May 11, 2005 11:57 pm
Posts: 80
A few points in no particular order, may or may not help:

I notice that in your mapping file, you define children as having a required parent, but I don't ever see where you call child.setParent(parent);

Try changing the inverse="true" in the parent to inverse="false" and see if that makes any difference

I think the most striking thing is that there is no INSERT statement anywhere in the generated SQL - if you figure that out, you'll probably have your solution.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 3:10 am 
Newbie

Joined: Mon Jun 06, 2005 8:21 am
Posts: 13
Hi and thank your for your reply. I tried to follow the example code provided in section 16.3. Apparently I am missing something. First I thought the example was in some way Hibernate 3:ish but at least the guide says 2.1.7.

I recall I have been trying the very same example before without success.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 3:12 am 
Newbie

Joined: Mon Jun 06, 2005 8:21 am
Posts: 13
Oh, the method addChild() in class Parent adds the Parent object to the Child object (copied from the example).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.