Three major frameworks of Java_Web: Hibernate database operations (III), java_webhibernate
Seven steps are required to operate the database using Hibernate: (1) read and parse the configuration file
Configuration conf = newConfiguration (). configure ();
(2) read and parse the ing information and create SessionFactory
SessionFactory sf = conf. buildSessionFactory ();
(3) open the Session
Session session = sf. openSession ();
(4) Start a transaction (addition, deletion, modification, and query operations are optional)
Transaction tx = session. beginTransaction ();
(5) Database Operations
Session. save (user); // or other operations
(6) commit a transaction (roll back the transaction)
Tx. commit (); (tx. rollback ();
(7) Disable session
Session. close ();
Note: This step is not required if the current_session_context_class parameter in the Hibernate configuration file is set to thread and the Session Instance obtained using the getCurrentSession () method of SessionFactory.
: