在hibernate with spring的顶部使用JPA有什么好处。我在谷歌上看到他们使用 JPA + Hibernate + Spring 的项目和主题很少,但我找不到很好的解释。
还有分别何时使用 JPA 和何时使用 Hibernate。
如果有人能帮助我理解,我真的很感激
最佳答案
JPA 使用标准化的 ORM 编程模型简化实体持久性。换句话说,它抽象了持久层,以减少应用程序代码和 ORM 提供程序之间的依赖关系。
此标准化 (JPA) 为您提供了一种在 Hibernate、OpenJPA 等 JPA 持久性提供程序之间切换的方法。
来自 Pro Spring 3(Clarence Ho):
JPA defines common set of concepts, annotations, interfaces, and other services that a JPA persistence provider should implement (all of them are put under the javax.persistance package). When programming to the JPA standard, developers have the option of switching the underlying provider at will, just like switching to another JEE-compliant application server for applications developed on the JEE standards.
关于你的其他问题
also individually when to use JPA and when to use Hibernate.
JPA 以增加复杂性为代价促进模块化。这种权衡是否值得取决于项目的复杂性。
Hibernate 缩小了 RDBMS 中的关系数据结构与 Java 中的面向对象模型之间的差距。这个成熟且经过测试的库使您可以使用对象专注于业务逻辑,并节省编写与数据库交互所需的样板代码的时间。
关于Spring 中的 Java Spring hibernate 和 JPA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14988214/