JPA和Spring Data JPA有什么区别? [英] What's the difference between JPA and Spring Data JPA?

查看:130
本文介绍了JPA和Spring Data JPA有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Spring Data-JPA和JPA之间的区别感到困惑.我知道JPA,它是使用流行的ORM技术将Java对象持久保存到关系数据库的规范.

换句话说,JPA提供了接口和其他ORM技术,实现了那些称为JPA提供程序的接口,例如Hibernate.

现在,Spring Data JPA到底是什么?

Spring Data JPA是否在JPA之上添加了更多功能(接口),并且仍然仅被指定还是JPA提供者?

我看到Spring Data JPA在存储库(DAO层:如果我没记错的话)周围工作.那么,我的意思是,使用"Spring Data JPA + Hibernate"或仅使用"Hibernate"定向有何不同?

解决方案

我看到Spring,JPA在存储库(DAO层:如果我没记错的话)周围工作.因此,我的意思是使用"Spring JPA + Hibernate"或仅直接使用"Hibernate"有何不同?

正如您所说, JPA 规范,而 Hibernate 是该规范的特定实现(这些实现通常称为提供商).通过使用Hibernate,您将自己与该提供程序联系在一起,从而限制了您在需要时自由切换到另一个选项的自由(例如,您想使用EclipseLink或ObjectDB来代替,因为Hibernate有一个会中断您的开发过程的错误).

引用 Spring Data JPA 文档:

实现应用程序的数据访问层已经很长一段时间了.必须编写太多样板代码.域类是贫乏的,并且不是以面向对象或域驱动的方式设计的.

同时使用这两种技术,使开发人员在富域模型的持久性方面的工作变得更加轻松.但是,实现存储库的样板代码数量仍然非常高.因此,Spring Data的存储库抽象的目标是显着减少为各种持久性存储实现数据访问层的工作量.

总而言之,它是在JPA的基础上添加了另一层抽象,这是一种定义基于标准的设计,以在Spring上下文中支持 Persistence Layer .这些定义的接口(Spring已知)提供框架使用JPA处理以​​提供结果的服务.您可以使用Spring可以扫描项目并找到它的方式定义存储库:

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

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

JPA Spring现在到底是什么.是Spring,JPA是在JPA之上添加了更多功能(接口),仍然仅被指定还是JPA提供者?

Spring Data JPA通过使用定义的提供程序来引用JPA规范,从而提供了实现内部支持的存储库的定义.

I am a bit confused about the difference between Spring Data-JPA and JPA. I know about JPA that it is a specification for persisting the Java Objects to a relational database using popular ORM technology.

In other words, JPA provides interfaces and other ORM technologies, implements those interfaces known as JPA provider e.g Hibernate.

Now, what exactly is Spring Data JPA?

Is Spring Data JPA has added some more functionality (Interfaces) over JPA and still it is specified only or it is also a JPA provider?

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

解决方案

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?

As you said, JPA is an specification while Hibernate is a particular implementation of that specification (these implementations are usually referred to as Providers). By using Hibernate you tie yourself to that provider restricting your freedom to switch to another option when required (for example, you want to use EclipseLink or ObjectDB instead because Hibernate has a bug that halts your development process).

Quoting Spring Data JPA's documentation:

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.

To sum it up, it is on top of JPA adding another layer of abstraction, kind of defining a standard-based design to support Persistence Layer in a Spring context. Those defined interfaces (known to Spring) provide the services that the framework handles using JPA to serve the results. You define a repository in a way Spring can scan the project and find it:

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

Thus, allowing you to use it in the context of a container or outside of it.

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?

Spring Data JPA provides a definition to implement repositories that are supported under the hood by referencing the JPA specification, using the provider you define.

这篇关于JPA和Spring Data JPA有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆