简体   繁体   中英

can we use jpa without hibernate

I am new to JPA.

As per my understanding, JPA is specification and Hibernate implements JPA and provide add on features along with JPA methods.

But I was going through JPA tutorials, where using EntityManager object we can perform CRUD on data, without using Hibernate libraries!

So can anyone please let me know

  1. Can I use JPA alone using EntityManager methods, not using Hibernate?

Please mention some useful link or example.

Much appreciate response.
Thanks.

You are right JPA is a specification. Hibernate, and EclipseLink are a couple of its implementations.

You have to specify the persistence provider(Hibernate, EclipseLink) in order to use the JPA implementation. The persistence providers have the implementation classes for JPA specifications.

You can't just use JPA, cause it is an API =), but there are plenty JPA implementations:

  1. EclipseLink
  2. ObjectDB

If you don't want to use Hibernate (or any other JPA provider), then you must implement your own provider, by giving an implementation for the javax.persistence.spi.PersistenceProvider interface. The question, is, why do you need re-invent the wheel ? If you don't like Hibernate, you can use one of the so many other JPA-Providers to choose from

JPA can be used without a JPA provider aka Hibernate, EclipseLink and so on only if the application server has already a JPA implementation. Most likely on the tutorials you have seen demos that were perfomed on such an application server.

Though this thread is pretty old, I felt it is worth breaking things down.

JPA: It Is just a specification. In simpler words. Set of interfaces.

Hibernate, Eclipse Link: Two of the many implementations of JPA. In addition to providing the basic implementations for the JPA specifications, Hibernate and Eclipse Link provide their additional functionalities. You can choose based on your need

Spring Data:

  • It provides additional abstraction.
  • When you use Hibernate/Eclipse Link you still have to write some boilerplate code. By using Spring JPA you can avoid that.
  • The most important thing to note is Spring data uses Hibernate by Default due to Springboot's Opinionated nature. You can change the default behavior if you would like.
  • When you run the following command in a Springboot project that uses Spring JPA(with default configuration), you will see Hibernate jars being used.

Maven: mvn dependency:tree

Gradle: gradle dependencies

You can use JPA alone without using Hibernate and Before should know about major points in between Hibernate vs JPA as given below.

Hibernate

  1. Hibernate is a ORM Framework which is support complete ORM and also use JPA features.
  2. Second level Cache is available so Performance is very good
  3. Its support .Net using NHibernate tool
  4. Its generate HQL(Hibernate Query Language)

JPA

  1. JPA is part of EJB specification which is released in J2EE 1.5 and this will use for java as well as J2EE
  2. Second Level Cache is not available so Performance is not good.
  3. Its not support to .Net
  4. Its generate JPQL(Java Persistence Query Language)
  5. Top of any persistence provider like Hibernate we can use JPA.

you can't use JPA on its own. JPA is a specification, which defines an API for object-relational mappings and for managing persistent objects and you need a JPA provider to implement it, like Hibernate, EclipseLink.

No, you cannot perform CRUD operations with JPA alone. As JPA is just a specification, you need the implementation to perform database operations. The implementations are provided by Hibernate, EclipseLink, Ibatis, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM