关于java:Spring Data-JPA与JPA:有什么区别?

Spring Data-JPA versus JPA: What's the difference?

我对Spring数据JPA和JPA之间的区别有点困惑。我知道JPA是使用流行的ORM技术将Java对象持久化到关系数据库的规范,换句话说,JPA提供接口和其他ORM技术,实现那些被称为JPA提供者(例如Hibernate)的接口。

现在什么是Spring数据JPA。SpringDataJPA是在JPA上添加了更多的功能(接口),还是只指定了它,还是它也是JPA提供程序?

我看到SpringDataJPA在存储库中工作(DAO层:如果我没有错的话)。所以我的意思是,使用"spring data jpa+hibernate"或者只使用"hibernate"指令有什么不同?


I saw Spring, JPA works around repositories (DAO layer: if I am not wrong). So I mean how it is different using 'Spring JPA + Hibernate' or only using 'Hibernate' directly?

如您所说,JPA是一个规范,而Hibernate是该规范的特定实现(这些实现通常被称为提供者)。通过使用Hibernate,您可以将自己绑定到该提供程序,限制您在需要时切换到其他选项的自由(例如,您希望使用EclipseLink或ObjectDB,因为Hibernate有一个阻止您的开发过程的错误)。

引用Spring数据JPA的文档:

Implementing a data access layer of an application has been cumbersome for quite a while. Too much boilerplate code had to be written. Domain classes were anemic and haven't been designed in a real object oriented or domain driven manner.

Using both of these technologies makes developers life a lot easier regarding rich domain model's persistence. Nevertheless the amount of boilerplate code to implement repositories, especially is still quite high. So the goal of the repository abstraction of Spring Data is to reduce the effort to implement data access layers for various persistence stores significantly.

总而言之,它位于JPA之上,添加了另一个抽象层,定义了一种基于标准的设计来支持Spring上下文中的持久性层。这些定义的接口(Spring知道)提供框架使用JPA来服务结果的服务。您可以用Spring扫描项目并找到它的方式定义存储库:

1
<repositories base-package="com.acme.repositories" />

因此,允许您在容器上下文或容器外部使用它。

Now what exactly is Spring, JPA. Is Spring, JPA has added some more functionality (Interfaces) over JPA and still it is specified only or it is also a JPA provider?

SpringDataJPA提供了一个定义,通过引用JPA规范,使用您定义的提供程序来实现引擎盖下支持的存储库。


The Java Persistence API, sometimes referred to as JPA, is a Java framework managing relational data in applications using the Java Platform, Standard Edition (JavaSE) and Java Platform, Enterprise Edition(JavaEE).

< /块引用>

在这方面的持续性包括三个方面:

  • javax.persistence包中定义的API本身。

  • Java持久性查询语言(JPQL)。

  • 对象关系元数据。enter image description here

Spring Data JPA is part of the umbrella Spring Data project that makes it easier to implement JPA based repositories.

< /块引用>

特征:

  • 对基于Spring和JPA构建存储库的复杂支持
  • 支持querydsl谓词,因此键入安全的jpa查询
  • 域类的透明审核
  • 分页支持,动态查询执行,能够集成自定义数据访问代码
  • 启动时验证@Query注释查询
  • 支持基于XML的实体映射
  • 通过引入@EnableJpaRepositories来配置基于javaconfig的存储库enter image description here