• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Basic Hibernate question regarding Bulk Insertions

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am working on an application what uses Hibernate to populate (initialize)a DB with a large web of interconnected objects. It has several many-to-many link tables, etc.. I don't have a problem with mapping the objects, but how to cleanly handle massive number of insertions using Hibernate's API.

I have followed the advice of the Hibernate docs and have a sythetic key assigned from a sequence in the DB. Now when I insert a duplicate object Hibernate has no problem inserting a new row in the DB with a new sequence id. If I give the Business Key a unique constraint an exception is thrown. Now I don't like the idea of finding out about a duplicate through an exception.

I was wondering what is the standard way that this situation is handled. Is it to first issue a Query (or get()) on the root object and every single member of its collections on each insert to make sure they don't exist and if they do reuse that object?

I know this is probably a very newbee question, but any guidance would be greatly appreciated.

thanks,
Roger
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This thread covers the downside of doing a query for a duplicate before performing the insert instead of using a unique index and responding to the exception. Long story short, there's a race condition that forces you to respond to the exception anyway, so you may as well put the duplicate-handling code in one place.
 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic