Hibernate learning: CRUD unit test cases + knowledge Summary
I. Use Cases
Ii. Summary
Main interfaces:
1: AnnotationConfiguration
2: SessionFactory
3: Session
Knowledge point:
1: configure can specify the path of the Hibernate file. If the Hibernate configuration file name is hibernate. cfg. xml, you do not need to write the file path.
2: factory. openSession (); each call creates a new session.
3: factory. getCurrentSession (); obtains the session from the context. If no session is created, a new session is created if no session is created.
4: factory. openSession (); close manually
Factory. getCurrentSession (); close is not required. When a transaction is committed, it is automatically closed.
5: factory. getCurrentSession (); you need to add the method to obtain the context in the Hibernate configuration file: thread is the most common method.
Thread
6. session Status
Transaction
Persistence
Detached
Differences:
Is there an id?
Is the session closed?
Is there a value in the database?
7: Two query methods
Load returns a proxy object. The SQL statement is executed only when the object attribute is obtained, delaying loading.
Get to get the SQL statement immediately. No Delay