inotgo.com

Example 1 : What is? HIBERNATE   
Example 2 : POJO What is it?   
Example 3 : HIBERNATE Development process   
Example 4 : one-many How to configure   
Example 5 : many-one How to configure   
Example 6 : many-many How to configure   
Example 7 : get With load The difference between   
Example 8 : Common query 3 Two ways   
Example 9 : Three states   
Example 10 : openSession With getCurrentSession The difference between   
Example 11 : 1 Level cache   
Example 12 : 2 How to configure level cache   

HIBERNATE It's a lightweight ORM Implementation of , Yes JDBC A package for .
ORM It means Mapping between objects and relational databases Object Relation Database Mapping.
POJO My full name is plain old java object
amount to JAVA BEAN, Also called entity class entity bean
Example 3 :

HIBERNATE Development process

edit top fracture
One complete hibernate Development process Include the following steps
1. to configure Hibernate.cfg.xml
It contains database connection information , Which? HBM, Whether to use 2 Level cache , Show SQL, Dialects, etc
2. to configure hbm File
Which class corresponds to which table , Property corresponds to what field , Various relationship mapping , For example ONE-MANY,MANY-ONE,MANY-MANY
3. use HIBNERATE
Through Configuration Get SessionFactory, Then get it Session, Then carry out a series of database related business operations
With Category and Product One to many is an example
1. Category One of them set of products
2. stay Category.hbm.xml There must be a one to many mapping in
<set name="products" lazy="false">
<key column="cid" not-null="false" />
<one-to-many class="Product" />
</set>
Detailed reference Hibernate Realize one to many
Or with Product and Category take as an example
1. Product One of them category attribute
2. stay Product.hbm.xml In conduct many-to-one to configure

<many-to-one name="category" class="Category" column="cid" />


Detailed reference Hibernate Realize many to one
Example 6 :

many-many How to configure

edit top fracture
With User and Product As an example
1. User There are products attribute
2. Product There are users attribute
3. Use the following to configure

<set name="products" table="user_product" lazy="false">
<key column="uid" />
<many-to-many column="pid" class="Product" />
</set>


For details, please refer to Hibernate Realize many to many
Example 7 :

get With load The difference between

edit top fracture
Through id obtain Product Objects have two ways , namely get and load
The difference between them is
1. Delayed loading
2. For id When it doesn't exist

For details, please refer to Hibernate GET and LOAD The difference between
The three are HQL, Criteria and standard SQL
Entity class object in Hibernate There are 3 Kind of state
They are instantaneous , Persistence and disconnection

instantaneous It means no and hibernate Any relationship , There is no corresponding record in the database , Once JVM end , The object disappears
lasting It refers to an object and hibernate Contact , Have corresponding session, And there is a corresponding record in the database
Off the pipe It refers to an object, although there is a corresponding record in the database , But it corresponds to session It's closed

Code demonstration reference Hibernate Three states of objects instantaneous lasting Off the pipe
Example 10 :

openSession With getCurrentSession The difference between

edit top fracture
Hibernate There are two ways to get session, namely :
OpenSession and getCurrentSession
The difference between them is
1. Whether the obtained is the same session Object
OpenSession Every time I get a new Session Object
getCurrentSession In the same thread , Get the same... Every time Session Object , But what is obtained in different threads is different Session Object
2. The necessity of transaction submission
openSession Only in increasing , Delete , Transactions are required when modifying , Not required for query
getCurrentSession Yes, all operations must be carried out in a transaction , And after the transaction is committed ,session It turns off automatically , Can no longer be closed

Code demonstration reference resources Hibernate OpenSession With GetCurrentSession The difference between
hibernate By default, the L1 cache is enabled , The L1 cache is stored in session Go ahead

Code demonstration reference What is? Hibernate L1 cache for
Example 12 :

2 How to configure level cache

edit top fracture
Hibernate The first level cache is Session Go ahead , L2 cache is in SessionFactory Go ahead

collocation method :
To be in hibernate.cfg.xml Middle opening

<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>


Example reference : How Hibernate of ehcache L2 cache configuration


The official account of programming , Follow and get the latest tutorials and promotions in real time , thank you .


Q & A area    
2020-07-16 nb The stationmaster made a ssm Yeah Make sense, these interview questions are too useful
jyzzzzzzZ

nb The stationmaster made a ssm Yeah Make sense, these interview questions are too useful







The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see




2019-03-13 The stationmaster begged ssm Interview questions
yty82639

The stationmaster begged ssm Interview questions







The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see




2019-01-10 What is lightweight ?
2018-12-20 as follows :
2018-06-10 Did the webmaster ssm Your interview questions


Too many questions , Page rendering is too slow , To speed up rendering , Only a few questions are displayed on this page at most . also 3 Previous questions , please Click to view

Please... Before asking questions land
The question has been submitted successfully , Auditing . Please My question Check the question record at , thank you
about Interview questions - Frame -hibernate Your questions

Try to provide Screenshot code and Abnormal information , Help to analyze and solve problems . You can also enter this station QQ Group communication : 496725845
Ask questions and try to provide complete code , Environment description , The more conducive to the recurrence of the problem , The faster your question can be answered .
Have questions about the code in the tutorial , Please provide which step , Which line is in doubt , This makes it easy to quickly locate the problem , Improve the speed at which questions are answered
In the thousands of questions that already exist , A considerable proportion , Because of the use of and webmaster Different versions of the development environment Resulting in , For example jdk, eclpise, idea, mysql,tomcat Wait, the version of the software is inconsistent .
Please use the same version as the webmaster , You can save yourself a lot of learning time . The webmaster sorted out the software versions used in teaching , It's all here , Convenient for everyone to download : /k/helloworld/helloworld-version/1718.html

Upload screenshot