2

I have one POJO in my Sample Hibernate Application and that points to table in my database. In my POJO class having @Entity annotation from JPA(javax.persistence.Entity).

What is the need of importance to place JPA annotation instead of Hibernate API.

Thanks in Advance...!

roeygol
  • 4,908
  • 9
  • 51
  • 88
jettisamba
  • 681
  • 2
  • 7
  • 14
  • what has Hibernate API got to do with anything? an annotation is an annotation not an API. Presumably the docs to the JPA implementation you have chosen would tell you the answer to that question ... – Neil Stockton Jan 28 '15 at 13:33

5 Answers5

5

I suppose this might be an answer to your question: What are the differences between Hibernate and JPA?

Using JPA annotations you can use any JPA provider, not only Hibernate, e.g. EclipseLink.

Community
  • 1
  • 1
Piohen
  • 1,514
  • 15
  • 23
1

Hibernate only has annotations for its proprietary features. For standard features (like declaring that a class is an entity, specifying its table name, etc.), it relies on standard JPA annotations.

That's a good thing, because if you only use standard JPA features, you should be able to use any other JPA implementation instead of Hibernate.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Standard argument. Falls down though because it's very very rare to switch ORM provider in this way. I've heard of it once or twice, but only ever switching to hibernate from some other, second rate, implementation. – Software Engineer Jul 09 '16 at 01:38
0

You use hibernate as implementation of JPA API. You should be able to change hibernate with another implementation (like EclipseLink) without changing in the code. This is why you should only use JPA annotations.

klagrida
  • 169
  • 1
  • 4
  • Who says that for any particular project one 'should' be able to switch out ORM provider? This argument simply isn't relevant to most projects as almost nobody ever switches away from hibernate. – Software Engineer Jul 09 '16 at 01:37
0

The advantage of using JPA annotation is JPA is an Oracle Java standard , it is always good to use a standards. What if tomorrow hibernate is no longer popular and another other ORM tool is coming up?

Software Engineer
  • 15,457
  • 7
  • 74
  • 102
Dapper Dan
  • 932
  • 11
  • 23
0

The real argument for using JPA is that most java developers will understand what you've written. Arguments suggesting that you may switch out provider/ORM are meaningless to most projects as this almost never happens. But, your code is probably going to be read by many different developers over its lifetime, and it would be good if you've used tools and techniques they already know, rather than some library nobody has ever heard of. In this case, JPA allows you to communicate with the future a lot more easily than the original hibernate annotations.

Software Engineer
  • 15,457
  • 7
  • 74
  • 102