This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inserting a batch of objects using Hibernate entity manager

 
Baalamurugan Raman
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

We are handling high volume of records (millions of it)
We need to use batch insert (1000) records in a single batch and to execute it
Could anybody help us on it. Its quite urgent

like List<ClassA> collA = new ArrayList

EntityManager em = getEM()
em.persist(collA);

Is it possible like this in Hibernate ? I refered hibernate site but its not relevant to it

Thanks in advance to
Java Gurus
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont think there's such a thing as batch insert.
I think if you are using Hibernate for inserting millions of records at the same time....you 'll have to go the normal way of insert and commit.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate support batch processing ( see here). Personally I would not use an ORM for high volume batch processing though, unless I had fairly complex business rules to apply. Databases come with much more performant bulk loading tools which are usually better suited.
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul for pointing out the mistake...
I was not really aware that such a thing as Batch Insert existed.
Thanks
 
Baalamurugan Raman
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I went through the link, so are you saying there is no batch concept in hibernate entity manager

Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
for ( int i=0; i<100000; i++ ) {
Customer customer = new Customer(.....);
session.save(customer);
}
tx.commit();
session.close();

Just have one doubt, when it calls session.save. Does it inserts the data everytime to the database ?
I feel its quite expensive process to save it in the db everytime the loop iteratest.
Or Is this the only way to save a single object or a batch of objects ?

Thanks in advance
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic