When i am doing sample Hibernate standalone program, little bit confusing was created in my mind with the usage of @Entity annotation.
Here my question is, I have one persisted class with @Entity from javax.persistence package then it's working fine but when i replaced @Entity annotation with Hibernate API(i.e from org.hibernate.annotations package) then it's giving org.hibernate.MappingException: Unknown entity: com.jetti.test.Employee
Give some more explanation are highly appreciated.
@javax.persistence.Entity is still mandatory, @org.hibernate.annotations.Entity is not a replacement.
Documentation
So, hibernate's @Entity
just complements the javax.persistence.Entity
, and gives a few more fine tuning options.
The difference is the same between Hibernate and JPA, rather JPA is just a specification, meaning there is no implementation, and Hibernate is an implementation.
You can annotate your classes with JPA annotations, but without an implementation nothing will happen.
In an abstract way you can consider "JPA" as the guidelines.
When you use Hibernate with JPA you are actually using the Hibernate by JPA implementation. The benefit is that you can swap out Hibernate's implementation of JPA for another implementation of the JPA specification (Eclipse Link, DataNucleuse,..) else if you use directly Hibernate you cannot just switch over to another ORM.
I hope that it was helpful.
JPA is not an ORM implementation but is just guidelines to implement the Object Relational Mapping (ORM) and there is no underlying code for the implementation. it will not provide any concrete functionality to your application. Its purpose is to provide a set of rules and guidelines that can be followed by JPA implementation vendors to create an ORM implementation in a standardized manner.
Hibernate is a JPA provider. When there is new changes to the specification, hibernate would release its updated implementation for the JPA specification. Other popular JPA providers are Eclipse Link (Reference Implementation), OpenJPA, etc. See Other provider here
@javax.persistence.Entity
is a GuideLine for a provider that implements JPA guideline
@org.hibernate.annotations.Entity
is an implementation for a Hibernate ORM
Futhermore you can see this other topic
The org.hibernate.annotations.Entity annotation is deprecated and it is scheduled for deletion:
@deprecated See individual attributes for intended replacements. To be removed in 4.1
Every attribute has a dedicated annotation (e.g. DynamicInsert, DynamicUpdate) and so you should always sue the javax.persistence.Entity alternative.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With