Which are the differences/similarities between hibernate and other frameworks or specifications?

萝らか妹 提交于 2019-12-18 18:33:43

问题


I want to know the differences/similarities between Hibernate and simple persistence in Java EE 5?

I'm not clear if Hibernate implements Java EE 5 persistence implementation or if it is a totally different approach to data representation over back-end systems.

I'm confused about Hibernate and its relation with the concepts about java persistence given in the Java EE 5 tutorial... could you clarify the role of Hibernate in the context of Entities and EJBs?

Also, I want to know other approaches (frameworks) like JPA or Spring...


回答1:


I want to know the differences/similarities between Hibernate and simple persistence in Java EE 5?

The standardized persistence API of Java EE 5 is JPA 1.0 and is a kind of unified version of EJB 2 CMP, JDO, Hibernate, and TopLink APIs and products. Hibernate is an ORM framework that predates JPA and has heavily influenced the specification of JPA (the creator of Hibernate is a member of the expert group behind JPA). Just keep in mind that JPA is just an API, you need an implementation of JPA to use it.

I'm not clear if Hibernate implements Java EE 5 persistence implementation or if it is a totally different approach to data representation over back-end systems.

Yes, Hibernate provides an implementation of JPA (and also extends it, Hibernate is a superset of JPA) via the Hibernate EntityManager project (that relies on Hibernate Core).

I'm confused about Hibernate and its relation with the concepts about java persistence given in the Java EE 5 tutorial... could you clarify the role of Hibernate in the context of Entities and EJBs?

Hibernate can be used as the JPA persistence provider, i.e. as the piece of code that actually persists EJB 3 entities (the JPA specification was part of EJB 3.0 specification in version 1.0, it's now a separate spec)

Also, I want to know other approaches (frameworks) like JPA or Spring...

Spring is not a persistence framework, Spring is an IoC container, it doesn't compete with Hibernate.

JPA compliant alternatives to Hibernate include TopLink Essentials (the RI in Java EE 5), EclipseLink (which is also the RI of JPA 2.0 in Java EE 6), OpenJPA, DataNucleus.

Other options for persistence include JDO (another standardized persistence API), iBATIS (not an ORM, it's more a data mapper), JDBC (low level API) to cite the most famous.

Check this previous answer for an overview and some historical background.




回答2:


When JPA (Java EE 5 persistence standard) was developed by the JCP expert group (JSR 220) a lot of ideas have been taken from the existing Hibernate (also from JDO). Gavin King the founder of Hibernate himself has been part of the expert group among others.

After the final JPA specification was published Hibernate became an open source implementation of it (since version 3.2). Hibernate still has a richer feature set and usually generates new features faster as an open-source development process tend to be faster then a Java community process.

Other implementations of JPA are:

  • DataNucleus
  • EclipseLink
  • OpenJPA

Other approaches are:

  • JDO
  • iBatis
  • plain JDBC



回答3:


The JPA specification described in EE5 is just an specification. This means that it is not a product. JPA is just a set of definitions that the different providers have to accomplish to be "JPA complaint"

Hibernate is just another "plugable" persistence provider, this means that this product implements the definitions given by JPA specification. You can find other similar products like TopLink or Apache's OpenJPA.

That is it.




回答4:


Slightly off topic but JPA implies a "session orientated" architecture. That is your beans are attached/detached to an EntityManager and you persist/merge/flush the entityManager.

If you are looking for a "sessionless" approach to ORM (no attached/detached persist/merge/flush) then you can also look at Ebean ORM which also uses JPA Annotations for mapping. You could also describe this as "Ebean provides automatic management of the Persistence Context".



来源:https://stackoverflow.com/questions/2723228/which-are-the-differences-similarities-between-hibernate-and-other-frameworks-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!