0

Till now I have a understanding that JPA is a specification and Hibernate is ORM tool based on that specification and we can have different implementations of JPA. But I could not understand how is it possible then that JPA 2 doesnot supports java.time.Instant but Hibernate 5.2x supports it.

I have read this question why-jpa-does-not-support-java-time-instant but it doesn't have proper answers and doesn't talks how hibernate is able to provide support for Instant being a JPA specific implementation.

Andronicus
  • 25,419
  • 17
  • 47
  • 88
Jaspreet Jolly
  • 1,235
  • 11
  • 26
  • 1
    Also, historically, there was Hibernate before JPA. JPA is mostly inspired by Hibernate. – Arnaud Denoyelle Feb 11 '19 at 15:55
  • 2
    FYI Instant was supported in other JPA providers (e.g DataNucleus) before Hibernate supported it. Why the JPA spec (2.2) didnt add support for it was down to Oracle (aka EclipseLink team) ... there was no "committee" just them, see this issue to get it supported https://github.com/eclipse-ee4j/jpa-api/issues/163 –  Feb 11 '19 at 15:59
  • JPA 2 is just an API, so it states only what must be supported, not what can or cannot be. So, Hibernate devs chose to support `Instant`, despite it not being explicitly mandated for them to do so. I'd assume they also support the mandated types properly. Main idea there is: Hibernate is not limited to only do what JPA2 requires, they can (and are, evidently) do more than that. Merits of that need to be discussed separately. – M. Prokhorov Feb 11 '19 at 16:32
  • ... for instance, considering that Hibernate is a superset of JPA features, one might tread carefully, as indulging in Hibernate-specific features might vendor-lock your app into being unable to treat JPA providers as external services to your app (as in, you can't just plug in any suitable JPA provider if you are using `Instant`s, you are locked into ones that support the type). – M. Prokhorov Feb 11 '19 at 16:37

1 Answers1

4

JPA is just a specification - it's a set of interfaces to provide common API. It describes the access to relational database to help developers manage multiple dbms vendors. There are multiple implementations of JPA, the reference is EclipseLink developed under Eclipse Public License. In other words it's a standard, like SQL-92 or SQL:2006. Databases that claim to support given standard can implement own features outside it to make data access easier.

In order to use JPA, we need an implementation. Besides EclipseLink the most common are Hibernate, OpenJPA and DataNucleus. All of them support JPA 2.2.

They implement the JPA specification but also provide additional functionalities to overcome some of JPA's shortcomings. Those functionalities are the main difference between implementations and make the code specific i.e. using, for example, Hibernate follows in code changes needed to be done when changing JPA specification. Only when using JPA we can switch between implementations. However I have never seen any project, that changed JPA vendor.

Andronicus
  • 25,419
  • 17
  • 47
  • 88