使用persistence.xml创建Session查询数据库?

Using persistence.xml to create a Session to query the database?

我熟悉使用 Hibernate 和 hibernate.cfg.xml 文件来创建 Session

但是,我的项目中有一个 persistence.xml 文件,而不是 hibernate.cfg.xml 文件。

我如何使用它创建一个 Session 然后我可以用它来查询我的数据库?

如果你想使用 persistance.xml,你应该使用 EntityManager。如何使用 EntityManager 您可以在 Hibernate, JPA – Part 1 教程中找到。

The key config file for JPA is persistence.xml. This lives in the META-INF directory. It details what the persistence driver to use and what JNDI data source to connect to. Additional properties can also be specified, in this case we’ll include some Hibernate properties.

下一拍大约是 Hibernate, JPA & Spring MVC – Part 2