-->
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 Performance
PostPosted: Wed May 06, 2009 11:21 am 
Newbie

Joined: Wed May 06, 2009 11:06 am
Posts: 1
Dear Hibernate community,

I want to insert a lot if of objects of the class "Characteristic" which has a manytoone relationship to "CharacteristicDefinitionType", but I'm having performance problems:

this.session.beginTransaction();
for (Map<String, String> row : table.getData()) {
CharacteristicDefinitionType cdt = session.createQuery("from CharacteristicDefinitionType where and name = ?").setString(0, row.get("DEFTP")).uniqueResult();
Characteristic characterstic = new Characteristic();
characterstic.setSapId(row.get("ELTUID"));
characterstic.setDefType(cdt);
characterstic.setName(row.get("MAPNAME"));
this.session.save(characterstic);
}
this.session.getTransaction().commit();

As you can see each time before inserting the characteristic object I've to fetch the corresponding characteristicdefinitiontype object by executing a query. Therefore in SQL it looks like this:
select * from characteristicdefinitiontype where ...
insert into characteristic ...
select * from characteristicdefinitiontype where ...
insert into characteristic ...
select * from characteristicdefinitiontype where ...
insert into characteristic ...
....

Now, having to execute a select statement before each insert operation makes this proccess very slow. Is it somehow possible (eg by caching) that it just makes a one-time select for all characteristicdefinitiontype objects?
select * from characteristicdefinitiontype
insert into characteristic ...
insert into characteristic ...
insert into characteristic ...
...


Top
 Profile  
 
 Post subject: Re: Slow Insert Performance
PostPosted: Wed May 06, 2009 4:28 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Of course it's possible, you could do that using one * query if the number of loaded entities is not too high, or better
take a look at the scrollable results API ;-)

http://docs.jboss.org/hibernate/stable/core/reference/en/html_single/#objectstate-querying-executing-scrolling

_________________
Sanne
http://in.relation.to/


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.