Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

inserting a batch of objects using Hibernate entity manager

 
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
 
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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE 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
 
If you're gonna buy things, buy this thing and I get a fat kickback:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic