What are the differences between Hibernate and JPA?

advertisements

When i was in college learning about web programming, they told us about hibernate.

We used it for a while, i even had the chance to work with it in a real scenario in a company for almost 8 months. Now that i completely switching to Java EE 6 (Im in love :) ), I use JPA for my ORM needs.

It is being a few months since i use it, but i dont really understand what are the differences between one and other. Why some people say one or other is better or worse? The way i do my mappings and annotations in both is almost the same...

Maybe you can solve some of my doubts:

-What are the advantages and dissadvantages of each?

-Does Hibernate uses JPA or the other way around(Do they depend on each other)?

-From the point of view of features, what features does one have that does not have the other?

-Any other differences between both?


JPA (Java Persistence API) is an API, JPA 2.0 is of the JSR 317 group. Basically it's a framework to manage relational data by using ORM (Object Relational Mapping) for data persistence.

Hibernate is a ORM library that maps your POJO/JavaBeans to your data persistence. Both ORM and JPA have a object/relational metadata (XML, Annotations) for mapping POJO's to DB tables.

Does Hibernate uses JPA or the other way around (Do they depend on each other)?

Hibernate 3 now supports JPA 2.0. JPA is a specification describing the relation and management of relational data using Object model. Since JPA is an API, Hibernate implements this API. All you have to do is write your program using JPA API classes/interfaces, configure Hibernate as a JPA resource and voila, you got JPA running.

What are the advantages and disadvantages of each?

Advantages:

  • Avoids low level JDBC and SQL code.
  • It's free (EclipseLink e.g. for JPA).
  • JPA is a standard and part of EJB3 and Java EE.

That's all I know of Hibernate.