使用Spring和Hibernate时,persistence.xml是否已经被请求? [英] Is persistence.xml requied when working with Spring and Hibernate?
问题描述
我正在使用Spring JPA和Hibernate的项目。大部分 persistence.xml 中的内容都可以在Spring applicationContext.xml文件中指定。
更新: Spring 3.1将支持 persistence.xml
- 免费的JPA配置,请参阅 Spring 3.1 M2:配置增强功能。
darioo的答案适合实际使用,但在技术上不正确。
Spring的 然而,获取 您可以使用 因此,实际上你可以通过编写一个自定义的 I am using a project with Spring JPA and Hibernate. Most of the things in persistence.xml can be specified in Spring applicationContext.xml file. So is the persistence.xml required anymore? Thanks. Update: Spring 3.1 will support darioo's answer is good for practical use, but not technically correct. Spring's However, process of obtaining You can configure the name of You can completely override the source of So, actually you can configure JPA in Spring without 这篇关于使用Spring和Hibernate时,persistence.xml是否已经被请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! PersistenceProvider
有两个工厂方法:
$ b $ ul
EntityManagerFactory createEntityManagerFactory(String emName,Map map) - 对于独立环境, PersistenceUnitInfo
传递。
LocalContainerEntityManagerFactoryBean
模拟应用程序服务器环境。因此,它解析 persistence.xml
本身,将其内容与应用程序上下文中的值合并,并使用第二种工厂方法将其传递给持久性提供程序。
persistence.xml
数据的过程是可配置的:
persistenceXmlLocation
属性来配置 persistence.xml
文件的名称 - 它是有助于避免与应用程序服务器的默认JPA初始化策略发生冲突。 PersistenceUnitInfo $ c的来源$ c $>通过设置自定义
PersistenceUnitManager
策略。
PersistenceUnitManager
来配置Spring中的JPA,而不需要 persistence.xml
,尽管这样的管理器是没有开箱即用。persistence.xml
-free JPA configuration, see Spring 3.1 M2: Configuration Enhancements.
PersistenceProvider
has two factory methods:
EntityManagerFactory createEntityManagerFactory(String emName, Map map)
- for standalone environments, persistence.xml
is to be parsed by persistence provider. EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map map)
- for application server environments, persistence.xml
was parsed by application server and its contents is passed as PersistenceUnitInfo
.LocalContainerEntityManagerFactoryBean
emulates the application server environment. Therefore it parses persistence.xml
itself, merges its contents with the values from application context, and passes it to the persistence provider using the second factory method.persistence.xml
data is configurable:
persistence.xml
file using persistenceXmlLocation
property - it's useful to avoid conflicts with the default JPA initialization strategies of application servers.PersistenceUnitInfo
by setting a custom PersistenceUnitManager
strategy.persistence.xml
by writing a custom PersistenceUnitManager
, though such a manager is not available out of the box.