Thursday, February 21, 2008

Advantages of Jpa over native hibernate

Jpa is the specification for persistence architecture in java and is implemented by various ORM providers like toplinks and hibernate.
JPA is not only annotations. There is also other differences, as configuration file named persistence.xml (should be placed in META-INF directory)
We can use hibernate in 3 modes:
  • core Hibernate
  • Hibernate with annotations
  • Hibernate as JPA provider

Hibernate as Jpa provider has certain advantages over other two...

It provides a standard, portable code. By portable, I mean we can change persistence provider without changing code! For example we can change Hibernate persistence into TopLink persistence without any modification Java files by just changing persistence.xml and jars.

Another advantage is possibility to use it with or without EJB, so you can use JPA on the JSE in the same way as on JEE.

But this approach has a disadvantage as well
Complex mappings cant be provided using jpa therefore we need to go back to native hibernate in that case..

No comments: