# [Differences between opensession and getcurrentsession]
<1> the generated session instance.
The session generated by opensession is an instance of sessionimpl;
Getcurrentsession generates a proxy object $ proxy
<2> New and Old session instances.
Each open opensession is a new session;
Getcurrentsession: the first call returns a new session, and then puts it into the thread context. Each time you get the same session that already exists in the context before the Transaction Completes [commit/rollback.
<3> auto-disable.
The opensession session needs to be closed manually;
The session of getcurrentsession is automatically closed internally when the transaction is completed, and you do not need to close it yourself in the code.
<4> usage conditions.
Use opensession;
Getcurrentsession must be configured with current_session_context_class in the hibernate configuration file; otherwise, usage fails.
<! -- Enable automatic session context management for hibernate --> <property name = "current_session_context_class"> thread </property>
# [Difference between get and load]
<1> delayed loading.
Get does not support delayed loading. It directly sends out SQL queries. Load delays loading and uses SQL queries to query databases only when object data is used.
<2> instance type of the returned object.
Get returns the original type of object instance; load returns the proxy object, $ response sist ..
<3> the object cannot be found.
Get query without data: NULL is returned directly, and nullpointerexception is returned during the call; load query without data: A proxy object is returned, which is the above $ Javassist.. org. hibernate. objectnotfoundexception.
# [Differences between SAVE and persist]
<1> the difference lies mainly outside the transaction.
Their main difference lies in the absence of transactions. If the SQL statement is issued immediately after the save operation is performed outside the transaction, the session contains the persistence Object ID, while persist does not issue the SQL statement. After the execution, the ID obtained immediately is 0, and no ID is returned immediately.