简体   繁体   中英

Setting up hibernate an JPA

I am new to ORM in Java. I have read about JPA, as I understood this is just specification and Hibernate implements this interfaces.
But I have some questions.

  1. If want to make my application more scalable I should use JPA configuration files. I mean that I should use persistence.xml instead of hibernate.cfg.xml ? Am I right ? Please provide an example of this configuration file for mysql.

    What is hibernate session ? Is it implementation of EntityManager ? Like implementation of interface. What should I use ? I read that if I use EntityManger it will use implementation of hibernate (Session) underhood. As I understood EntityManager is used for creating one connection to database. Like extended Connection instance ? Right ?

    I want make my application as scalable as it possible. I mean that if later I need to change implementation of JPA, for instance openJPA, I don't need to rewrite a lot of code.

I understand main concepts correctly ? Please suggest what is the best way to follow in this case.

JPA- JAVA Persistence API is the specification provided for managing relational databases.

Hibernate is an open source implementation of the Java persistence API. There are various other implemenatations available as well like toplink etc. If you use the specific configurations of Hibernate and annotations of hibernate your application would be tightly coupled to the specific implemenation. hence it is advised to follow JPA conventions so that if in future you wish to use some better implementation of JPA you can always do so and you application becomes loosely coupled.

JPA将使您的代码变得标准且可移植。它与性能无关。

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