curiousman
curiousman

Reputation: 67

Hibernate: Insert back a deleted row with the same ID

My Use Case:

  1. my Hibernate configuration using auto increment generator for insert and I don't want to change it.
  2. A user deleted a object with ID:10 and I saved this deleted object to somewhere.
  3. later on, user decide to restore this deleted object back with the same ID:10.
  4. since this object with ID:10 has been deleted from the database, How can I use Hibernate to insert it back to database while the hibernate configuration using auto increment generator(remember: I need keep the same ID for this object in database)?

Thanks,

Alex

Upvotes: 1

Views: 1063

Answers (2)

Amit Deshpande
Amit Deshpande

Reputation: 19185

I doubt Hibernate will not allow you to do this. However you can go and write sql queries to update Tables [If you have used Table Generator] to change the current index position that can be used but it will hell of complicated logic since you will always have to keep track on which index record is not present

Upvotes: 0

John Watts
John Watts

Reputation: 8875

I doubt Hibernate will let you do it if you don't change the generator. What about inserting it and then updating it with direct SQL and invalidating any hibernate caches?

Upvotes: 1

Related Questions