Lead to war paste, no nutrition, ignore.

More wonderful articles.

Microservices are not all, just a subset of specific domains

Selection and process should be careful, or it will get out of control.

With all these monitoring components, there’s always one that’s right for you

What the hell are we developing with Netty?

“This is probably the most pertinent Redis specification.”

Portrait of a Programmer: Ten Years of Ups and downs

Most useful series:

The Most Common set of “Vim” Techniques for Linux Production

The most Common set of “Sed” Techniques for Linux Production

The most Common set of “AWK” Techniques for Linux Production


SpringBoot development using Mybatis or Spring Data JPA?? “, a handy answer, a heated discussion. I really don’t understand why Spring Data JPA chose Hibernate as its implementation. Is it “Gavin King” nepotism? There is a reason why MyBatis is winning in the DAO layer, from JDBC to Hibernate, toplink to JDO.

At present, some bullshit training companies, and some online courses, including some foreign courses, in order to do simple projects, many will use JPA. But when I got to the company, I found that wasn’t the case at all. That’s the difference between theory and reality.

At the risk of being scolded, I sorted it out. This is not a debate about whether PHP is better or Java is better.

Advice: limited energy, must learn MyBatis ah. The WHOLE JPA thing, it’s just plain plain.

Here are the original answers

If you’ve been through multiple iterations of your company’s product, especially on complex projects, you’ll see how unflattering things like Spring Data JPA can be. To be honest, Mybatis sometimes has too many features, and some of them are simply gild the lily.

Jpa is a specification, but it is similar to Hibernate ORM (not to mention the use of some special scenarios).

Spring Data JPA is a toy, suitable only for a few simple mappings. I also have to mention the touted QueryDSL, which feels a little smart Aleck. I really don’t want to have to learn something thankless for a simple DAO layer.

List<Person> persons = queryFactory.selectFrom(person)
  .where(person.children.size().eq(
    JPAExpressions.select(parent.children.size().max())
  .from(parent)))
  .fetch();
Copy the code

Look at the query statement above. It’s not as clear as normal SQL. If there’s an emergency problem, damn it…

Jpa has many benefits, such as being independent of the underlying SQL. But I think Spring Data JPA has the following disadvantages:

1, masked the elegance of SQL, invented a query way of their own. This type of query does not cover all SQL scenarios.

2. Increased code complexity, requiring more time to understand daOs

DAO operations have become particularly decentralized, spread across multiple Java files, or annotations (although XML is also supported). Refactoring costs a lot if you do some scanning or optimization

4, do not support complex SQL, DBA process is not easy to cut into

Mybatis has some problems, but you’re more likely to be writing actual SQL. It is more lightweight than Spring Data JPA.

Once you’ve debugged your SQL elsewhere, you can simply write it to a configuration file, give it a name, and use it, much less brain-burning conversion.

Mybatis is fully capable of handling complex INDUSTRIAL SQL, even stored procedures (not recommended). I think Mybatis is still a bit complicated, it also adds some programming language features like if else.

If your company has a DBA, you are not allowed to mess with SQL. Using Mybatis can better cut into the process of the company.

So I think: toy projects or rapid development, using Spring Boot JPA. Instead, Mybatis is preferred.

Some useful comments

If else = SQL splice = SQL splice = SQL splice = SQL splice = SQL splice = SQL splice


Recently also in the study of persistence layer, can make full use of this JPA toy, the combination of the two is a good choice, JPA basic single table operation, MyBatis to do complex queries, high development efficiency, reduce THE cost of SQL maintenance, but also leave room for optimization, of course, this needs to do some extensions to spring-data-JPA


Query direct SQL, others or ORM convenient


Mybatis is mainly native SQL, which makes it easier for other developers who haven’t studied JPA to learn and maintain it.

Mybatis – Plus integration after the basic curd need not tangle, a lot of object operations and then directly save good. Use native SQL for complex scenarios and join tables, and use SQL advice for performance optimization.


JDBC Template + code generator, simpler and more efficient


This JPA thing, writing a simple database operation, like a single table operation, is great. If it’s multiple watches, forget it


Spring Boot recommends JPA. You know why


Native =true No one’s stopping you from using native queries


You don’t seem to know much about Hibernate and JPA…


I don’t know if you know the relationship between JPA, Hibernate, Spring Data JPA, and QueryDSL.


One day you’ll know the difference between database first and program first


Another benefit of JPA is that it’s pretty cool

END

Come on, the younger and the more arrogant you are, come on.