-->
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.  [ 5 posts ] 
Author Message
 Post subject: Using the same session for batch save
PostPosted: Wed May 17, 2006 3:10 pm 
Newbie

Joined: Tue Apr 04, 2006 9:56 am
Posts: 10
Hi All,
I am using Hibernate 2.1.6, In that to do batch insert, I retrive a new session each time for a TO and do the insert as below
for (Iterator iter = baseTos.iterator(); iter.hasNext();) {
to = (BaseTo) iter.next();
getSession().save(to);
}

Can I change this code to

Session ses = getSession();
for (Iterator iter = baseTos.iterator(); iter.hasNext();) {
to = (BaseTo) iter.next();
ses.save(to);
}

Basically Instead of getting new session for each save, I am using the existing session. What happens if one of the save fails??.




Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

_________________
Cheers,
Don't forget to rate the post, Thank You


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 3:27 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
Reference docs explain more how to do with batch save's
http://www.hibernate.org/hib_docs/v3/re ... batch.html


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 4:06 pm 
Newbie

Joined: Tue Apr 04, 2006 9:56 am
Posts: 10
Thank you for your reply. I am using Hibernate 2.1.6. And the document is for Hibernate 3. But I think the concept applies to Hibernate 2.1.6.

One thing I did not understood from the document is that, why do we need to do beginTransaction() and commitTransaction(). I am using Stateless Session Ejbs. Do we have to do this???.

Thank You
D

_________________
Cheers,
Don't forget to rate the post, Thank You


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 4:15 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
If you are using Container Managed Transactions, you dont need to do it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 4:16 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
If you are using Container Managed Transactions, you dont need to do it.


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