• 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

howto make sure delete successfully?

 
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark ,mind to show me some sample?
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic