• 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

Hibernate Multiple Insertion

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I am reading a input to the list. And after read is completed, I am inserting every object in the list by hibernate save method.
However, in the multiple save method call, hibernate throws an exception named;

org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session

When I add "clear()" method after save() method. The problem is solved, fine.
However, I think clear method wastes lots of time and I have to be quick.

So, what can I do?

Thanks
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without knowing exactly what you're doing, it's quite difficult to help--but obviously trying to save the same object more than once won't work. clear() is a cheap operation, by the way, although it would be better to understand why your code is doing something it shouldn't be.
 
pamir sonmez
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok let me more specific...

I am reading a xml file
then from this xml file I am creating objects and inserting this objects to the list.
After file read is finished, I am inserting every object to the database.

Since list have many objects(about 15000-20000), I want to insert object after read is completed.
Because read/insert one by one increases the operation time.

although it would be better to understand why your code is doing something it shouldn't be


I did not understand what you mean in here?

I am not doing anything wrong, I guess
Because the objects I want to save are different from each others however I am getting this error.
Online, I found some information that implies;


The cause is that object user1 is in detached state and is used in the second transaction to store the object, whilst there is already another object accociated. If you would not load object user2 the exception does not occur.



By the way, I wrongly clicked the "Resolved" button
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this what you need?
http://docs.jboss.org/hibernate/core/3.5/reference/en/html/batch.html#batch-inserts
 
Today's lesson is that you can't wear a jetpack AND a cape. I should have read 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