简体   繁体   English

在同一个应用程序中为同一个数据库一起使用 EntityManagerFactory 和 SessionFactory

[英]Using EntityManagerFactory and SessionFactory together at the same app for same database

Is it bad practice to use EntityManagerFactory and SessionFactory together at the same app for same database?在同一个应用程序中为同一个数据库同时使用 EntityManagerFactory 和 SessionFactory 是不好的做法吗? Or it's better to use only one of them?或者最好只使用其中一个?

EntityManageFactory is part of the JPA specification so it's more portable. EntityManageFactory是 JPA 规范的一部分,因此它更具可移植性。 SessionFactory is Hibernate specific but the implementation is a subclass of EntityManagerFactory anyway. SessionFactory是特定于 Hibernate 的,但无论如何实现都是EntityManagerFactory的子类。

Using one or the other (or both) depends on the requirements, how you create the factory and which API you prefer.使用其中一个(或两者)取决于要求、创建工厂的方式以及您喜欢哪种 API。 Hibernate will return an implementation that's compatible with both interfaces anyway.无论如何,Hibernate 将返回一个与这两个接口兼容的实现。

暂无
暂无

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

相关问题 如何使用相同的持久性单元使用 EntityManager 和 EntityManagerFactory 访问具有相同实体的不同数据源 - How to use same Persistence Unit to access different datasources with the same entities using EntityManager and EntityManagerFactory 使用 Hibernate SessionFactory 和 JPA EntityManager(一起) - Using Hibernate SessionFactory with the JPA EntityManager (together) Hibernate SessionFactory 与 JPA EntityManagerFactory - Hibernate SessionFactory vs. JPA EntityManagerFactory 在不同程序中同时使用同一数据库 - Using the same database at the same time in different programs GAE:Python和Java服务一起在相同的App ID下 - GAE: Python and Java services together under same App ID JPA Eclipselink-多个EntityManagerFactory实例返回相同的会话 - JPA Eclipselink - Multiple EntityManagerFactory instances returning same session 如何在上下文中存储sessionFactory对象并在整个应用程序中使用相同的对象 - How to store sessionFactory object in context and used same object whole application 使用Java将同一日期JSON数据分组在一起 - Grouping same date JSON data together Using java 允许Glassfish和PHP在使用Apache的同一服务器中协同工作 - Allow Glassfish and PHP to work together in the same server using Apache 无法初始化 JPA EntityManagerFactory:[PersistenceUnit:默认] 无法构建 Hibernate SessionFactory - Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM