I just do not optimistic about jpa

Know almost see the question "SpringBoot developed using Mybatis or Spring Data JPA ??", a handy A heated debate. I really do not understand why spring data jpa hibernate chose as its implementation, is "Gavin King" nepotism Why? DAO layer just kept on going, MyBatis win from jdbc to hibernate, toplink from the jdo, up to now, there is a reason.

At present, some shit training company, there are some online courses, including some foreign courses, in order to do simple projects, many of them will use jpa. But the company found that simply not the case, this is the difference between theory and reality.

Braved the risk of being criticized, I arrange to send out. This is not a good argument php or java a good nature.

Advice: energy is limited, we must first learn MyBatis ah. jpa the set, surface simple as that.

Below is the original answer

If you have experienced multiple iteration of the company's products, especially in complex projects, you will find Spring Data JPAthis kind of thing is not how to please. To be honest, Mybatisfunctional and sometimes are too many, and some simply superfluous.

jpaAlthough the norm, but, and hibernatethis ORMis more like the looks (do not say something specific usage scenarios).

Spring Data JPA is a toy, only suitable for simple mapping relationship . Also have to mention touted person querydsl, I feel some wiseacre easy way out. To really do not want a simple DAO layer, to learn some of the thankless things.

List<Person> persons = queryFactory.selectFrom(person)
  .where(person.children.size().eq(
    JPAExpressions.select(parent.children.size().max())
  .from(parent)))
  .fetch();
复制代码

Take a look at the above query, completely than ordinary SQLclarity of expression. If urgent investigation questions, Mom egg ...

Although jpa has many advantages, such as SQL and the underlying nothing to do. But I think the Spring Data JPA has the following disadvantages:

1, shielding the SQL elegance, invented a way to own query. This query is not able to cover all of the SQL scene.

2, increases the complexity of the code, need to spend more time to understand DAO

3, the special operation variants DAO dispersion dispersed to the plurality java file, or annotation (although support XML). If the number of scans, or optimized, large reconstruction costs

4, does not support complex SQL, DBA process is not good to cut

Mybatis although there are some problems, but more like you write in the exact SQL. It is more lightweight than the Spring Data JPA.

As long as you debug elsewhere good SQL, only you need to write to the configuration file, you can use a name, and a lot less brain burning of the conversion process.

Mybatis fully able to deal with complex SQL industrial-grade, or even stored procedures (not recommended). Personally I think Mybatis is still engaged in complex, which it also added some programming language features similar if else's.

If your company has a DBA, you are not allowed to mess with the SQL. With more Mybatis cut into the company's processes.

So I think: Toys project or the rapid development, the use of Spring Boot JPA. On the contrary, Mybatis is preferred.

Some useful comments

You said if else refers to the SQL stitching it, this is one of the important features of MyBatis, not at all complicated to learn, okay?


Recent studies also persistence layer, you can take advantage of this jpa this toy, a combination of both is a good choice, jpa basic single-table operation, mybatis do complex queries, high development efficiency and reduce maintenance costs sql, but also leave room for the optimization , of course, we need to do some extensions to the spring-data-jpa


Queries directly sql, or other convenient orm


mybatis mainly native sql, for other developers have not learned jpa reduces maintenance threshold learning, and really jpa wrote a pot you chase but it is still quite a headache ...

mybatis-plus after the integration of basic curd do not tangle, and many of the direct object manipulation and then save enough. Complex scene, directly associated with the native table sql like, as performance optimization problem can be represented by the following sqlAdvice.


jdbc template + code generator, simpler and more efficient


jpa this stuff, write a simple database operations, such as operating on a single table, very good use. If multi-table, then forget it


spring boot recommendation jpa, know why


native = true want to use native query and no one's stopping you ah


You seem to not really understand hibernate and jpa ...


I do not know if you know the relationship between jpa, hibernate, spring data jpa, there querydsl.


Someday you will know the database program priority and priority differences


jpa has another advantage, that is the handsome pot ah

END

Come, the more arrogant the younger guys to spray me ah.

Reproduced in: https: //juejin.im/post/5cf0f43bf265da1b86086e50

Guess you like

Origin blog.csdn.net/weixin_34293141/article/details/91438453