Records of the dao layer springboot

1, if the inheritance jpa JpaRepository, may be used in addition to crud method has been implemented, the method can also customize the rules findByXX XX parameters, use their own Baidu  

2, if MyBatis, if annotation @SelectProvider (custom sql, specify methods and classes)

3, if you do not use @SelectProvider a class of notes, you can also use @Select ( "select ***")

 

Add JPA HIBERNATE MYBAITS choice

1. Java Persistence API (Java Persistence API): API for the object persistence

2. effect: making applications in a uniform way to access persistence layer

3. preface mentions Hibernate, JPA and Hibernate then what to do with it:

1) JPA Hibernate is an abstract, like JDBC and JDBC driver relationship

2) JPA ORM is a norm, is a subset of the functionality of Hibernate (JPA since it is the norm, Hibernate for JPA was extended, so say JPA is a subset of Hibernate is not an exaggeration)

3) Hibernate is an implementation of JPA

4. JPA art including three aspects:

1) ORM mapping metadata, XML and support  JDK notes two forms of metadata

2) 的 JPA API

3) query language: JPQL

 

hibernate persistence is implemented technology, jpa persistence is standard, it is a specific implementation, an interface protocol is, of course, springdata jpa upper layer is implemented on the basis of the package on the hibernate.

More mature JPA framework includes the Jboss Hibernate EntityManager, Oracle donated to the community EclipseLink Eclipse, Apache's OpenJPA and so on.

 

 

 

I. Applications:

Traditional companies, some individual developers like to use jpa; and Internet companies prefer mybatis

the reason:

1, mybatis more flexible, iterative development model determines he is the first Internet companies; changes will not bring every drop in performance.

2, the traditional company needs iteration slow, small changes to the project, hibernate can be done once and for all; hibernate easily add relationships or because developers do not understand the cause optimization project, resulting in more change the more worse.

Second, their own characteristics:

1, mybatis official documents say that he is a semi-automated persistence framework, with respect to the automatic hibernate more flexible and controllable;

2, learning costs mybatis less than hibernate.

3, using hibernate requires a deep understanding of him, especially in terms of cache, as a persistence framework, performance is the first one.

hibernate has a three-level cache, a cache is enabled by default, you need to manually start the secondary cache and configuration optimization, the industry's popular three-level cache can be integrated caching technology: redis, ecache and so on.

4, hibernate lazy loading the associated query. (In development, it is not recommended to use too much foreign key to the related operating)

5, jpa is a specification, hibernate also comply with this specification;

6, springDataJpa is encapsulation of the repository, the repository simplified operation.
 

 

Use for some time jpa, and mybatis been used before, do not say what the difference is, because there are a lot of people compare the two frame! 
From domestic open source application framework, domestic use orm jpa do people still relatively small, if replaced hibernate will be more, so the risk is that you may be faced with, people you would not necessarily cooperate with, if to multi-party cooperation, we must consider this issue! 
Flexibility, jpa more flexible, including basic CRUD, the data in a relational database than mybatis and switching flexibility, but a higher threshold jpa, the other is to update the data need to first check out the data to be updated, the amount of data when, jpa efficiency will be lower, this time to do some extra work to deal with! 

 

1. Relatively speaking, jpa learning cost is slightly higher than mybatis 
2. The business needs change frequently leads to complex table structures used here mybatis more flexible than JPA 
3. dialect speaking on the general database changes very little after the company selected , so the advantage here dialects can be ignored

 

Many people favor Mybatis, because it provides a convenient SQL operations, high degree of freedom, the package is good ...... SpringData JPA complex SQL support is not good, do not join the two tables associated entities, really spend a lot of effort.

 

Talking to operate the database, can be divided into several stages: first stage JDBC, JDBC beginners may use the native JDBC API, and then may then use the database connection pool, such as: c3p0, dbcp, there are some third-party tools such dbutils etc., the landlord thought JDBC is through to the end, even to the frame part, will also JDBC to integrate this stage or their own handwritten SQL statements; the next stage is to Hibernate, we come to understand the operation of the database may not have to manually writing SQL , API can be called Hibernate provides.

 

Published 168 original articles · won praise 16 · views 90000 +

Guess you like

Origin blog.csdn.net/ajax_yan/article/details/104531574