Hibernate 和 Spring Data JPA 有什么区别 [英] What is the difference between Hibernate and Spring Data JPA

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

问题描述

Hibernate 和 Spring Data JPA 之间的主要区别是什么?我们什么时候不应该使用 Hibernate 或 Spring Data JPA?另外,Spring JDBC 模板什么时候比 Hibernate/Spring Data JPA 性能更好?

What are the main differences between Hibernate and Spring Data JPA? When should we not use Hibernate or Spring Data JPA? Also, when may Spring JDBC template perform better than Hibernate / Spring Data JPA?

推荐答案

Hibernate 是一个 JPA 实现,而 Spring Data JPA 是一个 JPA 数据访问抽象.如果没有 JPA 提供程序,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 为 DDD Repository 模式 或遗留的 GenericDao 自定义实现.它还可以通过方法名称约定代表您生成 JPA 查询.

Spring Data offers a solution to the DDD Repository pattern or the legacy GenericDao custom implementations. It can also generate JPA queries on your behalf through method name conventions.

借助 Spring Data,您可以使用 Hibernate、EclipseLink 或任何其他 JPA 提供程序.使用 Spring 或 Java EE 的一个非常有趣的好处是您可以使用 @Transactional 注释以声明方式控制事务边界.

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 更轻量级,它用于本地查询,如果您只想单独使用 JDBC,那么最好使用 Spring JDBC 来处理 JDBC 冗长.

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.

因此,Hibernate 和 Spring Data 是互补而非竞争.

Therefore, Hibernate and Spring Data are complementary rather than competitors.

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

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