One: See the test
Second: Knowledge points
Main interface:
1:annotationconfiguration
2:sessionfactory
3:session
Watch out.
1:configure can specify the path to the hibernate file, if the Hibernate profile name is Hibernate.cfg.xml, then you do not have to write the file path
2:factory.opensession (); each time a call is made, a new session will be created
3:factory.getcurrentsession (); Gets the session from the context, if one is not created, creates a new session if not
4:factory.opensession (); manual close Required
Factory.getcurrentsession (); Close is not required, and when a transaction commits, it is automatically close
5:factory.getcurrentsession (); You need to include a way to get context in the Hibernate configuration file: Thread is the most common one, from the current thread to find
<property name= "Current_session_context_class" >thread</property>
When to use factory.getcurrentsession ()
In transaction processing
Hibernate learning: The main API interface