Differences between HttpSession and Hibernate sessions 1. javax. servlet. http. httpSession is the generation of an abstract interface: When a J2EE Web program is running, an HttpSession is created for each new visitor, which is the unique expression of user identity. Note that the container (Tomcat, Resin) is automatically created. Purpose: store some frequently used information of this user, such as the user name and permissions. For example, in the shopping cart program, store the items bought by the user. Destroy: within a certain period of time (related to the container), the session is automatically destroyed without any action. Method: www.2cto. comHttpSession session = request. getSession (); common method setAttributesession. setAttribute (key, value); in this way, you can use session in another jsp or Servlet. getAttribute (key); The obtained value is similar to a Map 2, org. hibernate. session is a handle object for hibernate to operate databases. Its unique similarity with the above Session is that its name is a bit like anything else. In a general Hibernate program, the Session is manually obtained by the user and closed manually. In a regular project, obtain SessionSession session = HibernateSessionFactory. openSession () at the business layer, and then pass the session to the dao layer to persist data or perform other operations. A business logic may call multiple dao methods at a time. For example, bank transfer is a process of first subtraction and then increment. Therefore, two dao methods are called (account a subtraction, B ). Therefore, you can use the same Session generated by the business layer to do this. a1 and a2 represent the account entity. A1 is a and a2 is B. A1.setAcount (a1.getAcount ()-1000); a2.setAcount (a2.getAcount () + 1000); dao. update (a1, session); dao. update (a2, session); Transaction tx = session. beginTransaction (); tx. commit (); finally, close the session at the business layer. close (); or call HibernateSessionFactory. closeSession (session); it is best to add exception capture, and so on, such as exceptions, instant rollback. Ensure that the operation is not unexpected. Try {... tx. commit ();} catch (Exception e) {tx. rollback ();} finally {HibernateSessionFactory. closeSession (session);} the default session time is 20 minutes. If you want to clear the Session before this time, you can use the session. abandorn Method