mysql - how do i reinsert a deleted record with auto incremented id in hibernate java -
contact contact7 = new contact(7,"jobs", "jobsatapplet.com", "coffeebeans", "0123456789"); contact7.setid(7); //session.update(contact7); contact contact8 = (contact)session.load(contact.class, new integer(7)); contact8 = new contact(7,"jobs", "javaatapplet.com", "cupertino", "0123456789"); session.save(contact7); // commits transaction , closes session session.gettransaction().commit(); session.close();
this code, instead of reinserting record 7 inserts new record increments number of records duplicate values.
i not sure trying do, if update existing record, can this:
contact c = (contact)session.load(contact.class, new integer(7)); c.setlocation("cupertino"); session.gettransaction().commit(); session.close();
this is, if contact class has setlocation()
method. without mapping , class files can't more precise.
Comments
Post a Comment