-->
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: My script of inserting 50 rows takes several minutes
PostPosted: Sat Nov 25, 2006 12:39 pm 
Beginner
Beginner

Joined: Mon Sep 04, 2006 7:18 am
Posts: 45
Hello all.

I am just wondering if it is normal for a script to insert 50 rows in my database to take several minutes using Hibernate.

My database has 12 tables.
The thing I am wondering if it is correct to do is create a new Session each time I make an insert. I will not paste all my code, but here is how I insert into the database with each table.

Code:
kategori.setId("" + System.currentTimeMillis());
kategori.setKnavn(csv.get("kategori"));
session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
session.save(kategori);
session.getTransaction().commit();


This code I repeat for every table I have. What I am wondering is, is it correct to get the session, begin, save and commit each time?
I would guess it would suffice to create the session once, and commit at the end when the script is finished, and when I insert into tables, I just do something like this:
session.beginTransaction();
ssession.save();

But I get an exception saying session is not open when I try to beginTransaction.

Hope to get some answer so maybe my loading time will be reduced greatly.
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 27, 2006 2:07 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
50 inserts should not take several minutes. And you should keep all inserts in one transaction, this will save time. Turn SQL logging on to make sure there are only 50 insert queries. Maybe cascades are making more queries than you think. Only call beingTransaction() once (for each tx), call save for each object, then commit at end.

Chris


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.