What's the difference between Hibernate and JPA?

前端 未结 3 2000
南笙
南笙 2021-02-12 20:18

Can someone put in perspective the difference between JPA and Hibernate. Or are these complementary concepts, to be used together?

相关标签:
3条回答
  • 2021-02-12 21:13

    Update 2015: this is a very old question and a lot has changed in the past ~6 years. The JPA API's are quite feature-rich these days and I recommend using JPA since more and more tools and frameworks have aligned with it. One example is Spring Data JPA: it removes a lot of boilerplate for common tasks and is phenomenally productive:

    http://projects.spring.io/spring-data-jpa/

    Original Answer: I will echo cheng81's comments and also put in a vote for using the plain Hibernate APIs. The feature set of JPA is smaller than Hibernate's and I see no reason to handicap yourself with "pure JPA" just because it's a "standard."

    0 讨论(0)
  • 2021-02-12 21:15

    Roughly, JPA is a standard from the java community, here the specs, which has been implemented (and extended) by the Hibernate guys (some info here). Being a spec, you will not be using JPA directly, but a JPA implementation.

    Beware that if you'll use the hibernate JPAs' extensions, you'll break the compatibility with other JPA implementations (though some will say "why you should use another JPA implementation?").

    0 讨论(0)
  • 2021-02-12 21:20

    Hibernate is a really good solution, however its license (GPL) means it can't be used in some projects.

    JPA is a spec that supports a range of implementations including Hibernate, but also OpenJPA and other products with different characteristics.

    If you can get away with just using Hibernate, it may be worth doing so as its mature, stable and performs well. However, if you need to incorporate the persistence engine in a product that ships with a non-GPL license, you need to go the JPA route (or pay for the commercial Hibernate license).

    0 讨论(0)
提交回复
热议问题