What's the Difference Between JPA and Hibernate

Difference between Hibernate and Hibernate JPA

Indeed.

JPA is simply an API that allows you to abstract from the used persistence layer. Hibernate provides an implementation of the EntityManager interface that acts as an adapter - it uses the same underlying methods as a hibernate SessionManager.

The idea is that you could, for example, switch your implementation to Eclipse Link and not have to change any of your source code.

What is the difference between Hibernate and Spring Data JPA

Hibernate is a JPA implementation, while Spring Data JPA is a JPA data access abstraction. Spring Data JPA cannot work without a JPA provider.

Spring Data offers a solution to the DDD Repository pattern or the legacy GenericDao custom implementations. It can also generate JPA queries on your behalf through method name conventions.

With Spring Data, you may use Hibernate, EclipseLink, or any other JPA provider. A very interesting benefit of using Spring or Java EE is that you can control transaction boundaries declaratively using the @Transactional annotation.

Spring JDBC is much more lightweight, and it's intended for native querying, and if you only intend to use JDBC alone, then you are better off using Spring JDBC to deal with the JDBC verbosity.

Therefore, Hibernate and Spring Data are complementary rather than competitors.

What are the differences between Hibernate and JPA?

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.

similarity and difference between jpa and hibernate

JPA (Java Persistence API) is an interface for persistence providers to implement. Hibernate is one such implementation of JPA.

Spring + hibernate versus Spring Data JPA: Are they different?

Spring-data-jpa, as you're saying, offers more that just the classical Spring-JPA integration. With JPA/Hibernate integration, you get mainly

  • declarative transaction management using JPA/Hibernate transactions
  • exception translation
  • the JPA EntityManager or the Hibernate SessionFactory as injectable beans

With Spring-data-jpa, you get all that, plus (among other things)

  • interface-only repositories, using method names to infer queries automatically
  • @Query annotation to define the query that an interface method should return
  • automatic handling of Pageable queries
  • base classes for standard crud repositories

This is just a tiny introduction. For more help, read the documentation.



Related Topics



Leave a reply



Submit