• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Multiple Insertion

 
pamir sonmez
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • 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
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
hayden wangg
Greenhorn
Posts: 11
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic