Spring + hibernate 与 Spring Data JPA:它们有什么不同吗? [英] Spring + hibernate versus Spring Data JPA: Are they different?
问题描述
虽然不是新手,但我正在尝试学习 spring 框架(再次!)以确保我真的理解这一点.我对核心 Spring (DI) 有了很好的想法.现在,我专注于数据层.
Although not novice, I am trying to learn spring framework (again!) in order to be sure that I really understand this. I have got fair idea on core Spring (DI). Now, I am focusing on Data layer.
我遇到过Spring 和 Hibernate"这个词.正如我所理解的,这意味着使用 Spring Framework 和 Hibernate 作为 ORM 工具/JPA 提供程序.
I have come across the term "Spring and Hibernate". As I can interpret it would mean using Spring Framework with Hibernate as ORM tool/JPA provider.
现在我遇到了Spring Data JPA".我澄清了关于 Spring Data JPA 的 SO,它是 JPA 之上的一个抽象层(并且在底层 Spring Data JPA 使用 Hibernate 或任何其他 JPA 提供程序).
Now I have come across "Spring Data JPA". I clarified on SO about Spring Data JPA, that it is an abstraction layer on-top of JPA (and under the hood Spring Data JPA uses Hibernate or any other JPA provider).
现在这些术语相同吗?即,Spring + hibernate"与Spring Data JPA"相同.如果不是,那么有什么不同/相似之处?
Now are these terms same? That is, is "Spring + hibernate" same as that of "Spring Data JPA". If not, then what is the difference / similarities?
我对这么多看似相似但可能不同的术语/陈述(如上述)感到非常困惑.
I am really confused on so many terms/statements (like above) seemingly to be similar, but may be different.
推荐答案
Spring-data-jpa,正如您所说,提供的不仅仅是经典的 Spring-JPA 集成.通过 JPA/Hibernate 集成,您主要获得
Spring-data-jpa, as you're saying, offers more that just the classical Spring-JPA integration. With JPA/Hibernate integration, you get mainly
- 使用 JPA/Hibernate 事务的声明式事务管理
- 异常翻译
- 作为可注入 bean 的 JPA EntityManager 或 Hibernate SessionFactory
使用 Spring-data-jpa,您可以获得所有这些,以及(除其他外)
With Spring-data-jpa, you get all that, plus (among other things)
- 仅限接口的存储库,使用方法名称自动推断查询
- @Query 注解定义接口方法应该返回的查询
- 自动处理 Pageable 查询
- 标准 crud 存储库的基类
这只是一个小小的介绍.如需更多帮助,请阅读文档.
This is just a tiny introduction. For more help, read the documentation.
这篇关于Spring + hibernate 与 Spring Data JPA:它们有什么不同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!