programing

JPA와 Hibernate의 차이점은 무엇입니까?

nasanasas 2020. 9. 30. 10:57
반응형

JPA와 Hibernate의 차이점은 무엇입니까? [닫은]


JPA 2가 사양이고 Hibernate가 ORM을위한 도구라는 것을 이해합니다. 또한 Hibernate는 JPA 2보다 더 많은 기능을 가지고 있음을 이해합니다. 그러나 실제적인 관점에서 볼 때 실제로 차이점은 무엇입니까?

iBatis를 사용한 경험이 있으며 이제 Hibernate 또는 JPA2를 배우려고합니다. Pro JPA2 책을 집어 왔는데 "JPA provider"를 계속 언급하고 있습니다. 예를 들면 :

기능을 표준화해야한다고 생각하는 경우 JPA 제공 업체에이를 알리고 요청해야합니다.

이것은 나를 혼란스럽게해서 몇 가지 질문이 있습니다.

  • JPA2 만 사용하면 POJO에 주석을 달아 DB에서 데이터를 가져올 수 있습니다.
  • JPA2는 TopLink 또는 Hibernate와 같은 "JPA 공급자"와 함께 사용해야합니까? 그렇다면 JPA2 단독과 비교하여 JPA2 + Hibernate를 사용하거나 Hibernate 단독과 비교할 때 어떤 이점이 있습니까?
  • 좋은 실용적인 JPA2 책을 추천 해 주시겠습니까? "Pro JPA2"는 JPA2에 대한 성경 및 참고 자료처럼 보입니다 (책의 후반부까지 쿼리에 포함되지 않음). JPA2에 대한 문제 / 솔루션 접근 방식을 취하는 책이 있습니까?

JPA는 사양 일 뿐이므로 구현이 없습니다. JPA 어노테이션으로 원하는만큼 클래스에 어노테이션을 작성할 수 있지만 구현이 없으면 아무 일도 일어나지 않습니다. JPA를 따라야 할 지침이나 인터페이스로 생각하면 Hibernate의 JPA 구현은 JPA 사양에 정의 된 API를 충족하고 내부 기능을 제공하는 코드입니다.

JPA와 함께 Hibernate를 사용할 때 실제로 Hibernate JPA 구현을 사용하는 것입니다. 이것의 이점은 JPA 사양의 다른 구현을 위해 Hibernate의 JPA 구현을 교체 할 수 있다는 것입니다. 직선 Hibernate를 사용할 때 다른 ORM이 다른 방법 / 구성 및 주석을 사용할 수 있으므로 구현에 고정되어 있으므로 다른 ORM으로 전환 할 수 없습니다.

자세한 설명을 보려면 내 블로그 항목을 읽어보십시오 .


JPA는 댄스이고 Hibernate는 댄서입니다.


언어에 대한 역사적 관점과 JCP에 대한 이해 없이는 이해하기가 너무 어렵습니다.

종종 공식 JDK의 일부가 아닌 기능을 수행하거나 공백을 메우는 패키지를 개발하는 타사가 있습니다. 다양한 이유로 해당 기능이 JCP (Java Community Process)를 통해 Java JDK의 일부가 될 수 있습니다.

Hibernate (2003 년)는 SQL을 추상화하는 방법을 제공하고 개발자가 ORM (Persisting Object) 측면에서 더 많이 생각할 수 있도록합니다. Entity 개체에 대해 최대 절전 모드에 알리고이를 지속하기위한 전략을 자동으로 생성합니다. Hibernate는이를 수행하기위한 구현과 XML 구성 또는 주석을 통해 구현을 구동하는 API를 제공했습니다.

이제 근본적인 문제는 많은 사람들이 더 일반적이어야한다고 생각하는 것에 대해 코드가 특정 공급 업체 (Hibernate)와 긴밀하게 결합된다는 것입니다. 따라서 일반 지속성 API가 필요합니다.

한편, Hibernate 및 기타 ORM 도구 공급 업체로부터 많은 의견을받은 JCP는 JSR 220 (Java Specification Request)을 개발하여 JPA 1.0 (2006)과 결국 JPA 2.0 (2009) 인 JSR 317을 개발했습니다. 이것은 일반 Java Persistence API의 사양입니다. API는 JDK에서 인터페이스 세트로 제공되므로 클래스가 javax.persistence에 의존 할 수 있고 객체를 유지하는 작업을 수행하는 특정 공급 업체에 대해 걱정할 필요가 없습니다. 이것은 구현이 아닌 API 일뿐입니다. Hibernate는 이제 JPA 2.0 사양을 구현하는 많은 공급 업체 중 하나가되었습니다. JPA로 코딩하고 요구 사항에 적합한 호환 ORM 공급 업체를 선택할 수 있습니다.

Hibernate가 JPA에서 코드화되지 않은 기능을 제공 할 수있는 경우가 있습니다. 이 경우 JPA가 인터페이스를 제공하지 않기 때문에 Hibernate 특정 주석을 클래스에 직접 삽입하도록 선택할 수 있습니다.

출처 : http://www.reddit.com/r/java/comments/16ovek/understanding_when_to_use_jpa_vs_hibernate/


JPA 는 인터페이스이고 Hibernate는 구현입니다.

전통적으로 여러 Java ORM 솔루션이있었습니다.

고유 한 매핑 정의 또는 클라이언트 API를 정의하는 각 구현. JPA 전문가 그룹은 이러한 모든 도구의 장점을 모아 Java Persistence API 표준을 만들었습니다.

표준 지속성 API는 클라이언트 관점에서 매우 편리하므로 한 구현을 다른 구현으로 전환 하는 것이 비교적 쉽습니다 (실제로는 대규모 프로젝트에서는 특정 비표준 기능을 사용해야하기 때문에 그렇게 간단하지는 않습니다). .

표준 JPA는 Java ORM 경쟁을 새로운 수준으로 끌어 올렸으며 이는 더 나은 구현으로 이어질 수 있습니다.

으로는 설명 내 책, 고성능 자바 지속성 , 아직 JPA에서 지원하지 않는 최대 절전 모드 제공 기능 :

These extra features allow Hibernate to address many persistence requirements demanded by large enterprise applications.


From the Wiki.

Motivation for creating the Java Persistence API

Many enterprise Java developers use lightweight persistent objects provided by open-source frameworks or Data Access Objects instead of entity beans: entity beans and enterprise beans had a reputation of being too heavyweight and complicated, and one could only use them in Java EE application servers. Many of the features of the third-party persistence frameworks were incorporated into the Java Persistence API, and as of 2006 projects like Hibernate (version 3.2) and Open-Source Version TopLink Essentials have become implementations of the Java Persistence API.

As told in the JCP page the Eclipse link is the Reference Implementation for JPA. Have look at this answer for bit more on this.

JPA itself has features that will make up for a standard ORM framework. Since JPA is a part of Java EE spec, you can use JPA alone in a project and it should work with any Java EE compatible Servers. Yes, these servers will have the implementations for the JPA spec.

Hibernate is the most popular ORM framework, once the JPA got introduced hibernate conforms to the JPA specifications. Apart from the basic set of specification that it should follow hibernate provides whole lot of additional stuff.


JPA is just a specification which needs concrete implementation. The default implementation oracle provide is "Eclipselink" now. (Toplink is donated by Oracle to Eclipse foundation to merge with eclipselink)

(Reference : http://www.oracle.com/technetwork/middleware/toplink/index-085257.html http://www.eclipse.org/org/press-release/20080317_Eclipselink.php )

Using Eclipselink, one can be sure that the code is portable to any implementation if need arises. Hibernate is also a full JPA implementation + MORE ( Sort of JPA Plus). Hibernate is super set of JPA with some extra Hibernate specific functionality. So app developed in Hibernate may not be compatible when switched to other implementation. Still hibernate is choice of majority of developers as JPA implementation and widely used.

Another JPA implementation is OpenJPA (openjpa.apache.org) which is an extension of Kodo implementation.


JPA : is just like an interface and have no concrete implementation of it to use functions which are there in JPA.

Hibernate : is just a JPA Provider which have the implementation of the functions in JPA and can have some extra functions which might not be there in JPA.

TIP : you can use

     *combo 1* : JPA + JPA Provider(Hibernate) 
     *combo 2* : only Hiberante which does not need any interface 

Combo 1 : is used when you feel that your hibernate is not giving better performance and want to change JPA Provider that time you don't have to write your JPA once again. You can write another JPA Provider ... and can change as many times you can.

Combo 2 : is used very less as when you are not going change your JPA Provider at any cost.

Visit http://blog-tothought.rhcloud.com//post/2, where your complete confusion will get clear.


JPA is the interface, Hibernate is one implementation of that interface.


JPA is a specification to standardize ORM-APIs. Hibernate is a vendor of a JPA implementation. So if you use JPA with hibernate, you can use the standard JPA API, hibernate will be under the hood, offering some more non standard functions. See http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html_single/ and http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/


JPA is just a specification.In market there are many vendors which implements JPA. Different types of vendors implement JPA in different way. so different types of vendors provide different functionality so choose proper vendor based on your requirements.

If you are using Hibernate or any other vendors instead of JPA than you can not easily move to hibernate to EclipseLink or OpenJPA to Hibernate.But If you using JPA than you just have to change provide in persistence XML file.So migration is easily possible in JPA.


JPA is an API, one which Hibernate implements.Hibernate predates JPA. Before JPA, you write native hibernate code to do your ORM. JPA is just the interface, so now you write JPA code and you need to find an implementation. Hibernate happens to be an implementation.

So your choices are this: hibernate, toplink, etc...

The advantage to JPA is that it allows you to swap out your implementation if need be. The disadvantage is that the native hibernate/toplink/etc... API may offer functionality that the JPA specification doesn't support.


While JPA is the specification, Hibernate is the implementation provider that follows the rules dictated in the specification.


Java - its independence is not only from the operating system, but also from the vendor.

Therefore, you should be able to deploy your application on different application servers. JPA is implemented in any Java EE- compliant application server and it allows to swap application servers, but then the implementation is also changing. A Hibernate application may be easier to deploy on a different application server.


JPA is a specification that you implement in your data layer to perform db opertations, OR mappings and other required tasks.

Since it is just a specification, you need a tool to have it implemented. That tool can be either Hibernate, TopLink, iBatis, spring-data etc.

You don't necessarily require JPA if you are using Hibernate in your Data Layer. But if you use JPA specification for Hibernate, then it will make switching to other ORM tools like iBatis, TopLink easy in future, because the specification is common for others as well.

*(if you remember, you do import javax.persistence.*; when you use annotations for OR mapping (like @Id, @Column, @GeneratedValue etc.) in Hibernate, that's where you are using JPA under Hibernate, you can use JPA's @Query & other features as well)


JPA is a Java API specification which describes the management of relational data in applications using Java Platform. where as Hibernate is a ORM (Object Relational Mapping) library which follows JPA specification.

You can think JPA as a set of Rules which is implemented by Hibernate.


JPA is JSR i.e. Java Specification Requirement to implement Object Relational Mapping which has got no specific code for its implementation. It defines certain set of rules for for accessing, persisting and managing the data between Java objects and the relational databaseWith its introduction, EJB was replaced as It was criticized for being heavyweight by the Java developer community. Hibernate is one of the way JPA can be implemented using te guidelines.Hibernate is a high-performance Object/Relational persistence and query service which is licensed under the open source GNU Lesser General Public License (LGPL) .The benefit of this is that you can swap out Hibernate's implementation of JPA for another implementation of the JPA specification. When you use straight Hibernate you are locking into the implementation because other ORMs may use different methods/configurations and annotations, therefore you cannot just switch over to another ORM.


JPA is just a specification which needs concrete implementation. The default implementation provided by oracle is "Eclipselink" now. Toplink is donated by Oracle to Eclipse foundation to merge with eclipselink.

Using Eclipselink, one can be sure that the code is portable to any implementation if need arises. Hibernate is also a full JPA implementation + MORE. Hibernate is super set of JPA with some extra Hibernate specific functionality. So application developed in Hibernate may not be compatible when switched to other implementation. Still hibernate is choice of majority of developers as JPA implementation and widely used.

Another JPA implementation is OpenJPA, which is an extension of Kodo implementation.

JPA vs Hibernate


I try to explain in very easy words.

Suppose you need a car as we all know their are several A class manufacturer like MERCEDES, BMW , AUDI etc.

Now in above statement CAR(is a specification) as every car have common features like thing with 4 wheels and can be driven on road is car...so its like JPA. And MERCEDES, BMW , AUDI etc are just using common car feature and adding functionality according to their customer base so they are implementing the car specification like hibernate , iBATIS etc.

So by this common features goes to jpa and hibernate is just an implementation according to their jboss need.

1 more thing

JPA includes some basic properties so in future if you want to change hibernate to any other implementation you can easily switch without much headache and for those basic properties includes JPA annotations which can work for any implementation technology, JPQL queries.

So mainly we implement hibernate with JPA type technology just for in case we want to switch our implementation according to client need plus you will write less code as some common features are involved in JPA. If someone still not clear then you can comment as i m new on stack overflow.

Thank you


JPA is just a specification while Hibernate is one of the JPA provider i.e hibernate is implementing various things mentioned in JPA contract.


JPA or Java Persistence API is a standard specification for ORM implementations whereas Hibernate is the actual ORM implementation or framework.


JPA is Java Persistence API. Which Specifies only the specifications for APIs. Means that the set of rules and guidelines for creating the APIs. If says another context, It is set of standards which provides the wrapper for creating those APIs , can be use for accessing entity object from database. JPA is provided by oracle.When we are going to do database access , we definitely needs its implementation. Means JPA specifies only guidelines for implementing APIs. Hibernate is a JPA provider/Vendor who responsible for implementing that APIs. Like Hibernate TopLink and Open JPA is some of examples of JPA API providers. So we uses JPA specified standard APIs through hibernate.


Figuratively speaking JPA is just interface, Hibernate/TopLink - class (i.e. interface implementation).

You must have interface implementation to use interface. But you can use class through interface, i.e. Use Hibernate through JPA API or you can use implementation directly, i.e. use Hibernate directly, not through pure JPA API.

Good book about JPA is "High-Performance Java Persistence" of Vlad Mihalcea.

참고URL : https://stackoverflow.com/questions/9881611/whats-the-difference-between-jpa-and-hibernate

반응형