20191118001-Hibernate entry -Hibernate Introduction

1.1 Hibernate Introduction

1.1.1 Hibernate framework Introduction

1. Hibernate Framework

       Hibernate is a tool for data persistence, ORM is an open source solution. Hibernate encapsulates the internal operation of the database accessed by JDBC, provides object-oriented data access API to the upper layer.
       Hibernate is the founder Gavin King.

2. Hibernate is an ORM solution

       Based on ORM, Hibernate between the object model and relational database tables built a bridge, through Hibernate, programmers do not need to use SQL statements to manipulate database tables using the API directly manipulate objects can be achieved JavaBean persistence operations data the (store, query, change, and delete, etc.), this significantly reduces development costs because the object and relational database paradigm in terms of performance data does not match due.

1.1.2 Hibernate framework of the advantages and disadvantages and application scenarios

       If we ask Van database directly using the original JDBC way, the query returns a ResultSet object, and ResultSet objects often can not be used directly. Throughout the course of this inquiry, we need to convert a lot of repetitive work.Hibernate is used to achieve a lasting operation can be omitted and the cumbersome conversion frequent type codes using JDBC, As the following example code.

Session session=HibernateUtil.currentSession();
Query query=session.CreateQuery("from User");
List<User> users=(List<User>)query.list();

      In the above code HibernateUtil tool is a custom class for the object after the Hibernate Session, a Session persistence operations performed Hibernate core API. When Hibernate database query processing, code written in very simple. As a query result, a direct access to stored User List collection instance instance, can be used directly, avoiding the cumbersome reproducible data conversion process

1. Hibernate advantage frame
  • Hibarnate powerful bridge between Java used in relational databases, JDBC compared to manipulate the database, the code is greatly reduced, improving persistence code development speed, reduce maintenance costs.
  • Hibernate supports many object-oriented features, such as composition, inheritance, polymorphism, etc., so that the developer does not have to switch back and forth between the object model and the field of business-oriented relational data model for the database, to facilitate driving of the developer for the art object-oriented Design and Development,
  • Portability. The system will not be bound to a particular relational database systems for replacement of the database, usually only need to modify the Hibernate configuration file to run normally.
  • Hibernate framework open source and free. If necessary can be studied source code rewriting the source code, customized features, scalable.
2. Hibernate disadvantage frame
  • Not suitable for a large number of data-centric applications using stored procedures.
  • Large-scale bulk insert, modify and delete are not suitable for use Hibernate.

1.1.3 Hibernate and the comparison MyBatis

       Hibernate and ORM belong MyBatis framework, support operations of persistence data layer.

  • MyBatis relative to the "SQL-Mapping" of ORM implementation, Hibernate ORM achieve a more perfect, and provides state management functions. Hibernate operations on the data, for the Java objects, even using Hibernate Query Language (HQL statement), which is written in an object-oriented rule.
  • Hibernate and specific management database only needs to be configured in XML can, Hibernate developers need not be concerned with mapping SQL to generate the results, all the HQL statement has nothing to do with the specific use of the database, easy to modify, portability is good. The MyBatis direct SQL statements, there may be differences in different databases, modify the heavy workload, poor portability.
  • Since direct SQL statements, so the use of high flexibility of MyBatis, and Hibernate for the design of the relational model is unreasonable, non-standard system does not apply. MyBatis to the cache without considering the efficiency is higher than some of Hibernate.
发布了56 篇原创文章 · 获赞 17 · 访问量 6190

Guess you like

Origin blog.csdn.net/qq_43199016/article/details/103128781