• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

howto make sure delete successfully?

 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, i have a method which include serve 2 purposes , which is suppose delete the record first and then immediately insert



when i make only delete function , it does delete correctly, but if i do saving immediate after the delete , then it give me error like duplicate key error ...can someone pls enlighten me ...thank you
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your issue is that you are in the same session with the database, so you can still see the deleted record because the deletion has not been committed yet. Something along those lines. Because you still have the deleted record cached and therefore it "isn't deleted" to you yet until you commit.

Then I think you will be ok in the insert.

Mark
 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark ,mind to show me some sample?
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just a guess: try closing session before inserting

EDIT
i mean close after commit and then reopen to save and commit again
[ September 01, 2005: Message edited by: miguel lisboa ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or flush() the session. This forces any cached changes to be applied to the db immediately, rather than when the session is closed (as is the normal behaviour).
 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have try flush before , it seem not solve the problem
 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but i only put flush right just after the delete , i try put after delete and also insert again ...see whether it help ...
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nakata kokuyo:
i have try flush before , it seem not solve the problem


Hmm. Well, there are only a few things I can think of which could be causing a problem like this: possibly you are dealing with cached data (i.e. its all in the same session, so no DB operation has happened), or perhaps there is some transaction which has not been commited which means the delete hasn't happened by the time you try your insert, or somehow you are coding the insert before the delete. With that in mind, can you explain what you mean by "hibernate manager"? Is this the session, or is this something else?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic