One: Use Cases
Two: summary
Main interface:
1:annotationconfiguration
2:sessionfactory
3:session
Knowledge Points:
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>
6:session of three states
Transaction
Persistence
Detached
Difference:
There is no ID
Session has not closed
There are no values in the database
7: Two methods of querying
Load returns a proxy object that executes the SQL statement and delays loading when the object's properties are really being fetched.
Get executes and the SQL statement is immediately fetched. No delay
Hibernate learning: CRUD Unit Test Cases + Knowledge Summary