-->
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.  [ 1 post ] 
Author Message
 Post subject: Batch Insert without configuring hibernate.jdbc.batch_size
PostPosted: Wed Oct 28, 2009 3:30 am 
Beginner
Beginner

Joined: Mon Apr 23, 2007 8:30 am
Posts: 27
Location: India
I have been trying to understand the significance of the parameter hibernate.jdbc.batch_size. The following code works well even without mentioning the hibernate.jdbc.batch_size parameter in the configuration.

Code:
{
   Session session = HibernateSessionFactory.getSession();
   session.beginTransaction();
   for(int i=0; i<20; i++) {
      Address address = new Address();
      address.setAddressArea("Add - " + i);
      session.save(address);
      if (i==5) {
         System.out.println("Flushing Session...");
         session.flush();
         session.clear();
         System.out.println("Session Flushed");
         SessionStatistics sessionStatistics =session.getStatistics();
         System.out.println(sessionStatistics.getEntityCount());
         // Load address - Must be a DB Hit
         Address testAddress = (Address)session.get(Address.class, new Long(i));
         System.out.println(testAddress.getAddressArea());
      }   
   }
   session.getTransaction().commit();
}


In the above code, the session is flushed at
Code:
if (i==5)
When I retrieve the Address object at
Code:
Address testAddress = (Address)session.get(Address.class, new Long(i));
, it makes a DB hit and fetches the address object that was flushed. Everything is working fine as expected, so why do i need to set the parameter hibernate.jdbc.batch_size and flush the session only when the number of objects saved in session equals to the batch size. Apparently, the batch code above works fine even without configuring the hibernate.jdbc.batch_size parameter.

I am unable to undertand the significance of the parameter hibernate.jdbc.batch_size. Can anyone throw some light?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.