SoFunction
Updated on 2025-03-08

Detailed explanation of Hibernate examples for modifying data

Hibernate Modify data

1.Use HQL to update

Here, modify Person's name and age identification through the id

Session currentSession = ();
  ();
  //Create HQL  String hqlString = "update Person p set =? , =? where =?";
  //Build Query  Query query = (hqlString);
  //Set parameters  (0, "Xiao Ming");
  (1, 18);
  (2, 1);
  //renew  ();
  ().commit();

2 Use HQL to update

public void updateFunction2() {
  Session currentSession = ();
  ();
  //Create SQL  String sql = "UPDATE t_person_list SET name='cv',age=2 WHERE id=4" ;
  //implement  (sql).executeUpdate();
  //submit  ().commit();
  }

3 Use OID to update

 Session currentSession = ();
  ();

  Person person = new Person();
  (44);
  ("ccb");
  (90);

  (person);

  ().commit();

  • Use the () method to update the data according to the primary key. If the data exists, then it can be updated. If it does not exist, throw an exception and report an error.
  • You can use the (person); method to update the data according to the primary key. If the data exists, then it can be updated. If it does not exist, then insert is executed.

If you have any questions, please leave a message or go to the community of this site to exchange and discuss. Thank you for reading. I hope it can help you. Thank you for your support for this site!