Hibernate notes

newbaby2012 2022-02-13 08:17:21 阅读数:504

hibernate notes

hibernate The concept of

adopt sessionResistry Come on buildSession

sessionFactory adopt openSession establish session

session adopt beginTransaction To create transaction

session With cache

adopt flush, Before the transaction is committed (beginTransaction), Synchronize cached data to SQL, However, synchronization must be done by committing the transaction ,commit, To make the database change ; light flush It won't change the database

flush Will send SQL sentence , But the transaction is not committed

Persistent state

Temporary objects : be not in session, No more databases

Persistent object : stay session, Also in the database

Delete object : be not in session, No more databases , But the difference from temporary is , It was and is session too

Free object : OID Not for null, be not in session

 save Methods to summarize :

persist Methods to summarize : 

get() and load() contrast

Just tune get Will execute sql sentence , If the load, Then the query will not be executed immediately , Instead, it returns a proxy object , Delayed retrieval

If there is no corresponding record in the database table , and session It's not closed , be get return null,load Throw an exception

load Method , Lazy loading exceptions may be thrown ,LazyInitialzationException, such as session Closed ahead of time , Then the proxy object is gone

update Method

delete You can delete free objects and persistent objects

  Free object , And temporary objects , One difference is , Temporary objects id by null



Handle jdbc Of connection

Second level cache

Second level cache ,ecache It's used a lot , The isolation level needs to be configured , And which class

session There are three kinds of , Configure through properties , Choose

If it is bound to a local thread :

copyright:author[newbaby2012],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130817186006.html