开发者

Hibernate or JPA?

开发者 https://www.devze.com 2023-01-27 19:08 出处:网络
With Spring 3.0 is it recommended to use hibernate or JPA.What are the advantages and disadvantages of both of them when used with Spring 3.0 ?

With Spring 3.0 is it recommended to use hibernate or JPA.What are the advantages and disadvantages of both of them when used with Spring 3.0 ?

Note : We are als开发者_开发问答o suppose to use it with Spring Data Access.


I would say, JPA implementation provided by Hibernate. Why? Because

  • It would be easier to switch to some other JPA implementation later, if you you ever need to
  • Hibernate is the one of the major and most popular ORM around
  • Lot of books available
  • Extensive documentation, awesome reference material
  • Easy to get support on SO, and elsewhere

Actually, I don't mind to use Hibernate exclusive features too. I don't see any problem in sticking with Hibernate, just because its not an standard. And by the way, what makes you think Spring is standard. Its not, and you are fine with it, because it works. Similar thing can be said for Hibernate. Hibernate sometimes get hairy, if you don't know well what you are doing.


My preference is JPA with EclipseLink. Reasons:

  • JPA is standard, Hibernate is not
  • Use EclipseLink because JPA with Hibernate has some weird implementation. EclipseLink is also the reference implementation for JPA 2.0

Bozho: there are some that I found, unfortunately it is not so obvious because it only happens in some extreme cases. Some that I can think:

  • Convert JQL to CriteriaBuilder
  • ElementCollection works fine with JoinTable, which is wrong! ElementCollection should be accompanied by CollectionTable.


To be precise, you should use the Java Persistence API, and then you can use Hibernate as an implementation.

JPA without an implementation isn't worth anything.

JPA is a standard, so if you only use it's API, you can substitute Hibernate with some other JPA implementation. If you use some of Hibernate's specific API because you need functionality not provided with plain JPA, you'll have a vendor lock-in scenario, so you'll have to be careful about this.


It depends on our application.

If you are not sure that you will never need to change your persistence provider, it is strongly recommended to use JPA (2.0)

If you are sure that you never will change your persistence provider, than I recommend using JPA (2.0) too. But (only) in this case you have the possibility to use a proprietary feature of you choosen JPA-Provider, if you have a problem not solved by standard JPA. -- But use it wise, if you choose this way once, it is hard to go back!

Of course JPA is just an API - so you need an implementation of it. -- I used Hibernate as JPA provider, but mainly because I am allways in the second scenario (will never change it), and I needed additional features like Hibernate-Search and Envers.

0

精彩评论

暂无评论...
验证码 换一张
取 消