Java interview-Hibernate summary, java interview-hibernate
1. Hibernate Retrieval Method
Ø navigation object graph retrieval (navigation to other objects based on the loaded objects .)
OID retrieval (the object is retrieved Based on the OID of the object .)
Ø HQL search (using an object-oriented HQL Query Language .)
Ø QBC retrieval (using QBC (Qurey By Criteria) API to retrieve objects. QBC/QBE offline/online)
Ø local SQL retrieval (using the SQL query statement of the local database .)
Http://blog.csdn.net/lenotang/article/details/2596680
2. Object status in Hibernate
Ø temporary status (transient): It was just created with the new statement and has not been persisted yet, and is not in the Session cache. A Java object in the temporary state is called a temporary object.
Persistent state (persistent): Has been persisted and added to the Session cache. A persistent Java object is called a persistent object.
Ø detached: it has been persisted but is no longer in the Session cache. A Java object in the free state is called a free object.
Http://blog.csdn.net/communicate_/article/details/8452786
3. What are the three Retrieval Strategies of Hibernate, and the applicable scenarios?
Ø search now
Advantage: it is completely transparent to applications.
Disadvantage: the number of select statements is large.
Applicable: class level.
Ø delayed Retrieval
Advantage: The application determines which objects to load, which can avoid executing redundant select statements and loading unnecessary objects, saving memory space and improving retrieval efficiency.
Disadvantage: if an application wants to access a free-state proxy instance, it must be ensured that it has been initialized during persistence.
Applicable: one-to-many or many-to-many Association. Objects that the application does not need to access immediately or are not accessible at all.
Ø urgent left Outer Join Retrieval
Advantage: it is completely transparent to the application. no matter whether the object is in a persistent or free state, the application can easily navigate from one object to another object associated with it. When an external connection is used, the number of select statements is small.
Disadvantage: It may load objects that are not allowed to be accessed by the program. Complex Database Table connection image retrieval performance.
Applicable: one-to-one or multiple-to-one association. The object that the application needs to access immediately. The database system has good table connection performance.
Http://blog.csdn.net/adoocoke/article/details/8291966
4. The mismatch problem solved by the ORM (the mismatch between the domain model and the relational model)
Ø the domain model is object-oriented and the relational model is relational.
The domain model has an inheritance relationship, and the relational model cannot directly represent the inheritance relationship.
The domain model has many-to-many associations, and the relational model uses a connection table to represent many-to-many associations.
The domain model has two-way associations. The relational model only has one-way reference relationship, and always references one-way reference.
The domain model advocates fine-grained models and the relationship model advocates coarse-grained models.
5. Three Methods of Hibernate ing inheritance relationships
The entire inheritance system uses a table (tableper hierarchy)
Define a table for each subclass to store the unique attributes of the subclass (tableper subclass)
Ø each specific class has a table (union-subclass), which stores the complete information of sub-classes (table per concrete)
Http://blog.csdn.net/yanwushu/article/details/7680765
6. Differences between the find () method and the Query interface of the Session
Both the find () method and the Query interface of the Session class support the HQL retrieval method. The difference between the two lies in that the former is only a convenient way to execute simple HQL query statements, it does not have the function of dynamically binding parameters, and in Hibernate3.x, find () has been eliminated () the Query interface is the real HQL Query interface, which provides various Query functions listed above.
7. Hibernate Association Configuration
Ø one-to-one
Ø one-to-many
Ø many-to-many
Http://blog.csdn.net/lrain0813/article/details/5756015
8. Session features
It is not thread-safe. Therefore, when designing the software architecture, avoid sharing the same Session instance among multiple threads.
The Session instance is lightweight. The so-called lightweight means that it does not need to consume too much resources for creation or destruction. This means that the Session object can be created or destroyed frequently in the program. For example, a separate Session instance can be allocated for each customer request or a separate Session instance can be allocated for each unit of work.
Ø in a Session, each database operation is performed in a transaction, so that different operations (or even read-only operations) can be isolated ).
9 advantages of using XML files in Hibernate to configure object-link ing
Hibernate does not penetrate into the upper-layer domain model or the lower-layer data model. Software developers can independently design domain models without forcing them to comply with any specification. Database designers can design data models independently without forcing them to comply with any specification. Object-link ing does not depend on any program code. To Modify Object-link ing, you only need to modify the XML file without modifying any program, which improves the flexibility of the software, and makes maintenance more convenient.
Http://blog.csdn.net/it_man/article/details/1477317
10 The role of Session caching
Reduce the frequency of accessing the database. The speed at which the application reads persistent objects from the memory is much faster than that of querying data in the database. Therefore, the Session cache can improve the data access performance.
Ensure that the objects in the cache are synchronized with related records in the database. When the status of the persistence object in the cache changes, the Session does not immediately execute related SQL statements, which allows the Session to merge several related SQL statements into one SQL statement, in order to reduce the number of visits to the database, thus improving the performance of the application.
11 concurrent running of multiple transactions
Class 1 loss update
Ø dirty read
Ø virtual read/phantom read
Ø Repeatable read
Class 2 lost updates
Http://www.iteye.com/topic/791346
12 what is the difference between clearing and clearing sessions?
Session clearing cache refers to synchronously updating the database according to the changes in the state of the objects in the cache. (Hibernate includes three types of session Flush mode)
Clearing is to clear some or all objects of the session or disable the session;
Http://blog.sina.com.cn/s/blog_62a151be0100nf28.html
13. How does Hibernate work and why?
ØPrinciple
1. Read and parse the configuration file
2. Read and parse the ing information and create SessionFactory
3. Open Sesssion
4. Create transaction Transation
5. Persistent operations
6. Submit the transaction
7. Disable Session
8. Disable SesstionFactory
ØWhy?
1. The code for JDBC database access is encapsulated, which greatly simplifies the tedious and repetitive code at the data access layer.
2. Hibernate is a mainstream persistence framework based on JDBC and an excellent ORM implementation. He greatly simplifies the coding of the DAO layer.
3. hibernate uses the Java reflection mechanism instead of the bytecode enhancement program to achieve transparency.
4. hibernate has excellent performance because it is a lightweight framework. The flexibility of ing is excellent. It supports various relational databases, from one-to-one to many-to-many complex relationships.
Http://www.cnblogs.com/shanmu/p/3598477.html
14 Hibernate delayed Loading
1. Implementation of Hibernate2 delayed loading: a) entity object B) Collection type)
2. Hibernate3 providesDelayed attribute LoadingFunction
When Hibernate queries data, the data does not exist in the memory. When the program actually operates on the data, the object exists in the memory, and the loading is delayed, it saves the server memory overhead and improves the server performance.
Http://blog.163.com/xi_zh_qi/blog/static/8501594200812695053939/
15. Hibernate Cache Mechanism
1.Level 1 CacheIt is also called that the internal cache has Hibernate, which belongs to the application transaction-level cache.
2.Level 2 Cache
A) Application and Cache
B) distributed cache
Condition: the data is not modified by a third party, the data size is acceptable, the data update frequency is low, the same data is frequently used by the system, and non-critical data is used.
C) third-party cache implementation
Http://www.cnblogs.com/wean/archive/2012/05/16/2502724.html
16 optimized Hibernate
1. Use bidirectional one-to-Multiple Association instead of unidirectional one-to-Multiple Association
2. flexible use of one-to-multiple associations
3. Replace multiple-to-one instead of one-to-one
4. Configure the object cache without using the set Cache
5. Use Bag for one-to-multiple sets and Set for multiple-to-multiple sets
6. Use explicit polymorphism for inheritance classes
7. Fewer table fields, no more table Association, and secondary cache support
Http://blog.csdn.net/sprita1/article/details/9289971
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.