在Hibernate中访问实体对象在transaction.commit()之后会出现什么结果?

What will be the outcome if an entity object is accessed after transaction.commit() in Hibernate?

我是休眠新手。我想了解事务提交后的行为。考虑下面的代码-

员工 class 是 class,其对象将是 inserted/deleted to/from 数据库。

public static void main(String[] args) {

    SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
    Session session = sessionFactory.getCurrentSession();

     long id = 2;

 try {
    session.beginTransaction();
    Employee employee = (Employee) session.get(Employee.class, id);
    session.delete(employee);
    session.getTransaction().commit();
    employee.getName(); /*What will happen at this line*/
  }
  catch (HibernateException e) {
    e.printStackTrace();
        session.getTransaction().rollback();
 }
}

变成"Transient"。来自 Session class 文档

Persistent instances may be made transient by calling delete()

来自指南:

Transient - an object is transient if it has just been instantiated using the new operator, and it is not associated with a Hibernate Session. It has no persistent representation in the database and no identifier value has been assigned. Transient instances will be destroyed by the garbage collector if the application does not hold a reference anymore. Use the Hibernate Session to make an object persistent (and let Hibernate take care of the SQL statements that need to be executed for this transition).

查看此处了解更多信息https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/objectstate.html