简体   繁体   English

设置休眠JPA

[英]Setting up hibernate an JPA

I am new to ORM in Java. 我是Java新手。 I have read about JPA, as I understood this is just specification and Hibernate implements this interfaces. 我已经了解了JPA,据我所知这只是规范,而Hibernate实现了此接口。
But I have some questions. 但是我有一些疑问。

  1. If want to make my application more scalable I should use JPA configuration files. 如果要使我的应用程序更具可伸缩性,我应该使用JPA配置文件。 I mean that I should use persistence.xml instead of hibernate.cfg.xml ? 我的意思是我应该使用persistence.xml而不是hibernate.cfg.xml吗? Am I right ? 我对吗 ? Please provide an example of this configuration file for mysql. 请提供此配置文件的mysql示例。

    What is hibernate session ? 什么是休眠会话? Is it implementation of EntityManager ? 它是EntityManager的实现吗? Like implementation of interface. 类似于接口的实现。 What should I use ? 我应该使用什么? I read that if I use EntityManger it will use implementation of hibernate (Session) underhood. 我读到,如果我使用EntityManger,它将使用休眠(会话)底层实现。 As I understood EntityManager is used for creating one connection to database. 据我了解,EntityManager用于创建与数据库的一个连接。 Like extended Connection instance ? 像扩展Connection实例一样? 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. 我的意思是,如果以后需要更改JPA的实现(例如openJPA),则无需重写很多代码。

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. JPA-JAVA Persistence API是为管理关系数据库提供的规范。

Hibernate is an open source implementation of the Java persistence API. Hibernate是Java持久性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. 还有其他各种实现,例如toplink等。如果使用Hibernate的特定配置和hibernate的注释,则您的应用程序将与该特定实现紧密结合。 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约定,以便将来在将来希望使用更好的JPA实现时,始终可以这样做,并且应用程序会松散耦合。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM