2011-11-10 61 views
6

我們必須重命名persistence.xml才能使WebSphere 7不使用其內置的OpenJPA。配置Hibernate使用重命名的persistence.xml

這是很容易做到的,當你使用Spring,你只是責令其實體管理器工廠使用另一個位置的persistence.xml:

<property name="persistenceXmlLocation" value="META-INF/persistence-xxx.xml"/> 

但現在我們想用普通的Hibernate/JPA沒有Spring ,並找不到任何指定備用persistence.xml位置的方法。

JPA2規範沒有對它說什麼......

任何線索?是否可以指示Hibernate使用重命名的persistence.xml?

======

看來,它是不可能使Hibernate的讀取改名persistence.xml文件。 在我的情況下沒有必要。

回答

3

據我所知,這是不可能改變persistence.xml文件的位置。

也看看這個文件:Alternate JPA Providers in WebSphere Application Server,好像你應該能夠在persistence.xml文件中指定它,並在你的應用程序中嵌入所需的罐子使用Hibernate作爲JPA提供者。

確保您的persistence.xml被指定Hibernate作爲JPA提供者:

<persistence> 
    <persistence-unit name="myapp"> 
     <provider>org.hibernate.ejb.HibernatePersistence</provider> 

你也應該能夠通過創建一個共享庫,並用它來配置的WebSphere使用替代的持久性提供實現這一目標。 在這裏你可以找到如何做到這一點:Configuring the Java Persistence API (JPA) default persistence provider

編輯 鑑於在這個答案的評論信息,看來問題可以通過在persistence.xml添加這些特性來解決,因爲在這個崗位Websphere EntityManagerFactory creation problem表示:

<property name="hibernate.transaction.manager_lookup_class" 
value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" /> 

<property name="hibernate.transaction.factory_class" 
value="org.hibernate.transaction.CMTTransactionFactory" /> 

在WebSphere Application Server文檔中的備用JPA提供程序中也提供了相同的信息。

+0

謝謝!這將涉及額外的安裝程序,每次我們安裝應用程序,編寫指令等,但如果我們沒有找到其他方式,這是唯一的選擇 - 我們必須這樣做... –

+0

此外,採取看看這個文件:在WebSphere Application Server替代JPA提供商(HTTP:///www.ibm.com/developerworks/mydeveloperworks/wikis/form/anonymous/api/library/53181ccd-bcd4-431f-b968-0b5f6d46d652/文件/ 192a432b-28bb-4080-b037-345e5d83da76 /附接/ 61e74f67-1d60-4120-BA25-ad7264c9f4f6 /媒體/ AlternateJPAProviders_TestReport.pdf)。看起來你應該能夠通過在persistence.xml中指定'provider'並通過在你的應用程序中嵌入所需的jar來使用hibernate。看到我的答案編輯。 –

+0

Xavi,我們確實指定了提供者...但它只是導致'服務器無法爲jar:file:/ C:/ IBM/WebSphere中的org.hibernate.ejb.HibernatePersistence提供程序爲xxx持久性單元創建一個EntityManagerFactory工廠/wp_profile/installedApps/XXX/xxx-ear.ear/xxx-ejb.jar!/ module.'它可能是一個單獨的問題當然... –

0

persistence.xml中應該在META-INF目錄中,通常沿着封裝包含實體類的JAR文件。我所做的是在eclipse下的一個獨立項目中使用實體類,包含persistence.xml的META-INF目錄,將其打包成jar文件,並將其包含在應用程序項目依賴項中(即WEB-INF/lib),或者直接將它部署到應用服務器。

相關問題