What is the difference between Hibernate and Spring Data JPA?
Hibernate is a JPA implementation, while Spring Data JPA is a JPA data access abstraction. Spring Data JPA cannot work without a JPA provider. Spring Data offers a solution to the DDDRepositorypattern or the legacy GenericDao custom implementations. It can also generate JPA queries on your behalf through method name conventions. With Spring Data, you may use Hibernate, EclipseLink, or any other JPA provider. A very interesting benefit of using Spring or Java EE is that you can control transaction boundaries declaratively using the @Transactional annotation. Spring JDBC is much more lightweight, and it’s intended for native querying, and if you only intend to use JDBC alone, then you are better off using Spring JDBC to deal with the JDBC verbosity. Therefore, Hibernate and Spring Data are complementary rather than competitors.
- JDBC(Java DataBase Connectivity): Java连接数据库操作的原生接口。
- JDBC Template: Spring对原始JDBC封装之后提供的一个操作数据库的工具类。
- JPA(Java Persistence API): ORM框架的统一接口标准、通过注解或者XML描述【对象-关系表】之间的映射关系,并将实体对象持久化到数据库中。
- ORM(Object Relational Mapping): ORM是一种思想。建立实体类和数据库表之间的关系,从而达到操作实体类就相当于操作数据库表的目的。
- Spring Data JPA: 对JPA规范的抽象,底层使用Hibernate实现。
- Hibernate: 实现JPA规范的ORM框架。
- Mybatis: 也是一个持久层框架。可以进行更细致的SQL优化,查询必要的字段,但是需要维护SQL和查询结果集的映射,而且数据库的移植性较差,针对不同的数据库编写不同的SQL。Mybatis不完全是一个orm框架,不是依照的jpa规范,她需要些sql语句,半ORM。
各个适用场景:
如果是进行底层编程,需要对性能要求高,应采用 JDBC 方式。 如果直接操作数据库表,没有过多的定制,建议使用 Hibernate 方式。 如果要灵活使用 sql 语句,建议采用 MyBatis 方式。
持久层框架:负责操作 Connection、Statment、ResultSet,程序员只需关注SQL逻辑。

参考文章:
jdbc、jpa、spring data jpa、hibernate、mybatis之间的关系及区别
来说说JPA、Hibernate、Spring Data JPA之间都是什么关系呢
