Ole*_*eev 6 java hibernate jpa-2.0
我们必须重命名persistence.xml以欺骗WebSphere 7而不使用其内置的OpenJPA.
使用Spring时很容易做到,只需指示其实体管理器工厂为persistence.xml使用另一个位置:
<property name="persistenceXmlLocation" value="META-INF/persistence-xxx.xml"/>
Run Code Online (Sandbox Code Playgroud)
但是现在我们想在没有Spring的情况下使用普通的Hibernate/JPA,并且找不到任何方法来指定备用的persistence.xml位置.
JPA2规范没有说明任何事情......
有线索吗?是否可以指示Hibernate使用重命名的persistence.xml?
======
似乎让Hibernate读取重命名的persistence.xml文件是不可能的.在我的情况下没有必要.
据我所知,无法更改文件的位置persistence.xml。
另请查看此文档:Alternate JPA Providers in WebSphere Application Server,看起来您应该能够通过在文件中指定 Hibernate 作为 JPA 提供程序persistence.xml,并将所需的 jar 嵌入到您的应用程序中。
确保您的 persistence.xml 将 Hibernate 指定为 JPA 提供程序:
<persistence>
<persistence-unit name="myapp">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
Run Code Online (Sandbox Code Playgroud)
您还应该能够通过创建共享库并使用它来配置 WebSphere 以使用替代持久性提供程序来实现此目的。您可以在此处找到操作方法:配置 Java Persistence API (JPA) 默认持久性提供程序
编辑
鉴于此答案中的注释中的信息,似乎可以通过在 中添加这些属性来解决问题persistence.xml,如这篇文章Websphere EntityManagerFactory 创建问题中所示:
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" />
<property name="hibernate.transaction.factory_class"
value="org.hibernate.transaction.CMTTransactionFactory" />
Run Code Online (Sandbox Code Playgroud)
WebSphere Application Server 中的备用 JPA 提供程序文档中也提供了相同的信息。
| 归档时间: |
|
| 查看次数: |
6724 次 |
| 最近记录: |