The three states of an entity class object

1. Transient state: There is no id value in the object, and the object is not associated with the session
User u = new User();
u.setUsername("jack");
u.setPassword("123");
u.setAddress("china");


2. Persistent state: the id value in the object, the object is associated with the session
User user = session.get(User.class, 2);


3. Managed state: The object has an id value, and the object is not associated with the session
User user = new User();
user.setUid(3);


saveOrupdate() method: When the entity class is in transient state, this method performs the add operation. When the entity class is in the managed state, this method performs the update operation. When the entity class is in the persistent state, it also performs the update operation

Note
: The persistent state will The general modification method to automatically update the database :
User user = session.get(User.class, 2);//先获取
user.setUsername("Eastern Invincible");//Modify again
session.update(user);//Final submission


Now just need:
User user = session.get(User.class, 2);//先获取
user.setUsername("Eastern Invincible");//Modify again


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326048654&siteId=291194637