Spring Data-JPA与JPA:有什么区别? [英] Spring Data-JPA versus JPA: What's the difference?

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

问题描述

对于Spring Data-JPA和JPA之间的区别我有点困惑。我知道JPA,它是一个使用流行的ORM技术将Java对象持久化到关系数据库的规范,换言之,JPA提供了接口和其他ORM技术,实现了被称为JPA提供者的接口,例如Hibernate。

现在到底什么是Spring Data JPA。 Spring Data JPA是否通过JPA添加了一些更多的功能(Interfaces),并且它仍然是仅指定的,或者它也是JPA提供者?



我看到了Spring Data JPA存储库(DAO层:如果我没有错)。所以,我的意思是,它是如何使用'Spring Data JPA + Hibernate'或仅使用'Hibernate'指导的? $ b

我看到Spring,JPA在存储库周围工作(DAO层:如果我没有错的话)。所以我的意思是,它是如何使用'Spring JPA + Hibernate'或者直接使用'Hibernate'?

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



引用 Spring Data JPA 文档:


实现应用程序的数据访问层很麻烦有一会儿。必须编写太多的样板代码。域类是贫乏的,并没有被设计成真正的面向对象或域驱动的方式。



使用这两种技术使开发人员在富域模型持久性。尽管如此,实现知识库的样板代码数量仍然相当高。因此,Spring Data存储库抽象化的目标是减少为各种持久性存储实现数据访问层的工作。


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

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

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


现在到底什么是Spring,JPA。是Spring,JPA已经在JPA上增加了一些更多的功能(接口),它仍然只是被指定的,或者它也是一个JPA提供者?


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


I am 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 i.e. 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.

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

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