-->
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.  [ 2 posts ] 
Author Message
 Post subject: Slow insert of 10k child records in a one-to-many join.
PostPosted: Mon Feb 14, 2005 11:49 am 
Newbie

Joined: Mon Feb 14, 2005 10:59 am
Posts: 3
Location: Wilmington, DE
I’m testing an insert of one parent record and 10,000 child records into a mySQL (v. 4.1.9-standard) database using a one-to-many join via Hibernate 2.1 and am getting transaction times in excess of 20 minutes! I see that Hibernate...
(1) inserts the parent record,
(2) inserts the child records without the parent id, and then
(3) updates each child record with the parent id.

This third step is approximately 98% of the total transaction time. How can I eliminate this update step and have the parent id included in the original insert of the child records (step #2)? Any help would be enormously appreciated!

-- Michael Ceci

Hibernate version: 2.1

Name and version of the database you are using: mySQL 4.1.9-standard

parent.hbm.xml:
Code:
<hibernate-mapping>
        <class name="com.test.Parent" table="parent_table">
                <id name="id" column="parent_id" type="long" unsaved-value="null">
                        <generator class="increment"/>
                </id>
                <property name="name" column="parent_name"/>
                <set name="children"  cascade="all" inverse="false">
                        <key column="parent_id"/>
                        <one-to-many class="com.test.Child"/>
                </set>
        </class>
</hibernate-mapping>


child.hbm.xml:
Code:
<hibernate-mapping>
<class name="com.test.Child" table="child_table">
              <id name="id" column="child_id" type="long" unsaved-value="null">
                        <generator class="increment"/>
                </id>
                <property name="name" column="child_name" type="string"/>
        </class>
</hibernate-mapping>


Java Code:
Code:
Set childrenSet = new HashSet();
Child child = null;
for(int i=0; i < 10000; i++) {
   child = new Child("Child Name" + Integer.toString(i+1));
   childrenSet.add(child);
}
Parent parent = new Parent("Parent Name", childrenSet);
long startTime = System.currentTimeMillis();
try {
   log.debug(" >>> You're in AlertServiceImpl.insert()!! <<<");
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
   session.saveOrUpdate(alert);
tx.commit();
   session.close();
} catch (HibernateException e) {
       System.out.println(e.toString());
throw e;
}
long stopTime = System.currentTimeMillis();
System.out.println("TRANSACTION TIME = " + (stopTime - startTime) + " milliseconds);


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 12:03 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
http://blog.hibernate.org/cgi-bin/blosx ... find&path=


have in mind what is a session...

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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