-->
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.  [ 3 posts ] 
Author Message
 Post subject: Bulk insert/save possible?
PostPosted: Wed Aug 02, 2006 10:27 am 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
Hi,
We are using Hibernate3. We have a set of hibernate object(of same type) which we are saving something like:

Code:
while(someCondition) {

MyHibernateObject obj = MyUtil.createHO();
//save the object. This save API is called as part of the loop
getCurrentSession().save(MyHibernateObject.class.getName(),obj);

}


Is there an better way to do this? Is there some way by which i can pass my set of objects(of the same type) to be saved in one go? Some thing like bulk insert?

My code would look like:
Code:
Set myHOs = new HashSet();
while(someCondition) {

MyHibernateObject obj = MyUtil.createHO();
//just add the object to a Set, to save later in one go
myHOs.add(obj);

} //end of loop
//save all the objects, that were created earlier, in one go
getCurrentSession().save(MyHibernateObject.class.getName(),myHOs);


The reason i am trying this approach is to improve the performance.
Any help is appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 10:32 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
The insert statements are issued only when transaction is committed. So , in my opinion, it doesnt affect performance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 10:38 am 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
Quote:
The insert statements are issued only when transaction is committed. So , in my opinion, it doesnt affect performance.


Thanks for that info, bkmr_77. That helped.


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