Introduction: Hibernate in the processing of complex database query operations, such as multiple table association and packet Ordering, the inherent o-r mapping mechanism produces a large number of redundant SQL operations, and the system performance is much lower than the traditional JDBC. This paper analyzes the causes of such problems in Hibernate, proposes a solution to directly operate JDBC interface within the Hibernate framework, and verifies that the solution can effectively improve the efficiency of such queries in the actual project. The sample code provided in this article can be used directly for the Java EE System project using the Hibernate framework.
The reason for directly manipulating the JDBC interface in the Hibernate framework
The Hibernate framework's problems with complex queries
Hibernate is an open source Object Relational mapping framework that has a very lightweight object encapsulation for JDBC, allowing Java programmers to manipulate the database with arbitrary object-oriented programming thinking. Hibernate's advantage is to shield the details of the database, for the new modification of the deletion of the data layer operation, no longer need to deal with the specific SQL statements, simple to the object instance of the operation can be deleted.
However, for multiple table association, grouping statistics, sorting and other complex query functions, because Hibernate own o-r mapping mechanism, the correlation between parent-child table data will produce a lot of redundant query operations, low performance. In such cases, the SQL statements that use JDBC directly are more flexible and efficient.
Case analysis of complex query problem with Hibernate framework
Consider the following database entity examples, table A for the main table, table B and table C for child tables, A and B, a and C tables are 1 pairs of relationships, in B and C tables with the A_ID foreign key field associated with A table parent record.
Figure 1. Database Entity Sample diagram