Mainly summarize Hibernate from the following dozen aspects, including Hibernate's retrieval method, the status of the object in Hibernate, what is the three retrieval strategies of Hibernate, which occasions are applicable, the problem that ORM solves does not match, Hibernate mapping inheritance inheritance inheritance inheritance inheritance inheritance The three ways of relationships, the summary of the Find () method of session and the difference between the Query interface, etc. The specific content is as follows:
1 Hibernate search method
索 Navigation object diagram search (according to the loaded object, navigation to other objects.)
按 OID search (retrieves the object according to the OID of the object.)
使用 HQL retrieval (using an object -oriented HQL query language.)
使用 qbc search (using QBC (QBC (QBC (QBC (QBC (QBC (QBC (QBC (QBC (QBC (QBC (QBC (QBC (QBC (QBC (QBC (QBC (QBC (QBC (Qurey By Criteria) API) API) to retrieve objects. QBC/QBE offline/online)
索 Local SQL retrieval (SQL query statement using local database.)
Including Hibernate's retrieval method, the state of the object in Hibernate, what is the three retrieval strategies of Hibernate, which occasion for which occasions are applicable, the problem that ORM solves does not match, the three methods of the hibernate mapping inheritance relationship, the found () method of session () method of session And the summary of the differences in the difference between the Query interface
T Transient: Just created with the New statement, has not been persisted, and is not in the cache of the session. Java objects in a temporary state are called temporary objects.
(Persistent: It has been persisted and added to the cache of the session. Java objects in a persistent state are called persistent objects.
E Detached: It has been persisted but no longer in the cache of the session. Java objects in a free state are called free objects.
3 What are the three retrieval strategies of Hibernate, and which occasion is applicable to which occasions are applicable
Ø Immediate retrieval
Advantages: completely transparent to the application.
Disadvantages: SELECT statements are many.
Applicable: class level.
Ø Delayed retrieval
Advantages: What objects are loaded by the application to avoid the execution of excess selective statements and avoiding objects that do not need to be loaded, saving memory space and improving retrieval efficiency.
Disadvantages: If the application is to access the agent instance of the defive state, it must be ensured that it has been initialized when it is durable.
Application: one -to -multiple or more associated. Applications do not need to be accessible immediately or do not access at all.
接 Urgent left and outer connection search
Advantages: It is completely transparent to the application. Regardless of whether the object is in a persistent state or a free state, the application can easily navigate from one object to another. With external connections, the number of SELECT statements is small.
Disadvantages: The objects that may not be accessed may be loaded. Complex database table connection image search performance.
Application: one -to -one or more associated. Applications need to be accessed immediately. The database system has good table connection performance.
4 ORM solved the problem of non -matching (the do not match between the domain model and the relationship model)
向 The domain model is object -oriented, and the relationship model is related.
The domain model has inheritance relationships, and the relationship model cannot directly represent the inheritance relationship.
There are many relationships in the 多 domain model, and in the relationship model, the connection table is used to represent more and more associated relationships.
双 The domain model has a two -way relationship. There is only one -way reference relationship in the relationship model, and always Many refers to the ONE side.
精 The domain model promotes the fine particle size model, and the relationship model advocates coarse -size models.
5 Hibernate mapping in 3 ways of inheritance relationship
系 The entire inheritance system uses a table (Tableper Hierarchy)
张 Each subclass has a table, stored the unique attributes of the subclass (Tableper Subclass)
张 Each specific class (Union-Subclass), saved as a table full information (Table Per Concrete)
6 SESSION Find () method and the difference between the Query interface
The Find () method of the session class and the Query interface support the HQL retrieval method. The difference between the two is that the former only executes some convenient methods for simple HQL query statements. It does not have the function of dynamic binding parameters, and in the Hibernate3.x version, the Find () method has been eliminated; and the Query interface is the one is the Query interface. The real HQL query interface provides the above -mentioned various query functions.
7 Hibernate association configuration
One -on -one
Ø ø ø ø ø
Ø ø ø ø ø
8 Briefly describe the characteristics of session
, Not threads are safe, so when designing software architectures, multiple threads should be avoided to share the same session instance.
实 SESSION instance is lightweight. The so -called lightweight refers to its creation and destruction without consuming too much resources. This means that the session object can be created or destroyed regularly in the program, such as to allocate a separate session instance for each customer, or to allocate individual session instances for each working unit.
On In session, each database operation is performed in a transaction, so that you can separate different operations (even read only).
9 Hibernate uses the XML file to configure the object-the advantages of the relationship mapping
Hibernate neither penetrates into the upper domain model nor penetrate into the lower data model. Software developers can independently design domain models without force to obey any specifications. Database designers can independently design data models without force to comply with any specifications. Object-Relationship mapping does not depend on any program code. If you need to modify the object-relationship mapping, you only need to modify the XML file. You do not need to modify any program, improve the flexibility of the software, and make maintenance more convenient.
10 The function of the cache of session
库 Reduce the frequency of access to the database. The speed of the application from the memory from the memory is obviously faster than the speed of querying the data in the database, so the session cache can improve the performance of data access.
对 It guarantee that the object in the cache is synchronized with the relevant records in the database. When the state of the persistent object in the cache changes, the session does not immediately execute the relevant SQL statement, which enables Session to combine several related SQL statements into a SQL statement in order to reduce the number of access databases and increase the application Program performance.
11 The problem of more than the runtime of more affairs
新 The first type of loss update
Dirty reading
Ø ø ø ø/Phantom Reading
Ø Do not read repeatedly
新The second type of loss update
12 The difference between cleaning and emptiness of session
清 SESSION Cleaning Caches means updating the database synchronously according to the changes in the state of the cache;
S Clear is the session to clear part or all objects or session;
13 Hibernate's working principle and why
Primary
1. Read and analyze the configuration file
2. Read and analyze the mapping information, create sessionFactory
3. Open session
4. Create transaction transmission
5. persistent operation
6. Submit a transaction
7. Close session
8. Close SeSStIONFACTORY
Ø Why do you use
1. Packaged the code of JDBC's access to the database, which greatly simplifies the tedious repetitive code of the data access layer.
2. Hibernate is a mainstream and persistence framework based on JDBC, and it is an excellent ORM implementation. He largely simplifies the coding work of the DAO layer
3. Hibernate uses the Java reflection mechanism instead of bytecode enhanced program to achieve transparency.
4. Hibernate's performance is very good because it is a lightweight framework. The flexibility of mapping is excellent. It supports various relationship databases, from one to one to more complex relationships.
14 Hibernate delay load
1. Hibernate2 delay loading implementation: A) Sport object B) Collection type
2. Hibernate3 provides a delay loading function of the attribute
When Hibernate query the data, the data does not exist and the memory, and when the program really operates the data, the object exists and the memory is delayed. He saves the server's memory overhead, thereby increasing the server Performance.
15 Hibernate's cache mechanism
1. The first -level cache is also called the internal cache Hibernate, which belongs to the application transaction class cache
2. Second -level cache
a) Application and cache
b) distributed cache
Conditions: The data will not be modified by a third party, the data size is in acceptable range, the data update frequency is low, and the same data is frequently used by the system and the non -critical data.
c) The realization of the third party cache
16 Optimize Hibernate
1. Use two -way one -to -many associations, do not use one -to -one pair
2. Flexible use of one -way one -to -multiple association
3. No one -to -one, replace it with more pairs
4. Configuration object cache, no collection cache
5. One -to -multi -collection use BAG, most of the multi -collection use set
6. Inheritance classes are used for multi -state
7. There are fewer table fields, do not be afraid of the association of tables, there are second -level cache supporting the waist
The above is a common summary of Hibernate, which is more common in Java interviews, hoping to help everyone.