2012-06-29 107 views
0

我有一個應用與JPA Hibernate沒有春天,我需要連接到多個數據庫(具有相同的結構)。多個數據庫與JPA休眠沒有春天

將爲每個客戶端創建數據庫,並且必須使用相同的實體管理器。請給我一些關於如何做到這一點的想法。我不使用Spring。我的應用程序使用MySql,JPA2,Hibernate和JSF。

謝謝!

回答

1

如果一切都是相同的,除了dbname/username/pass,然後創建一個持久單元的persistence.xml,把所有靜態的。

然後用下面的方法來創建實體管理器:

javax.persistence.Persistence.createEntityManagerFactory(String persistenceUnitName, Map properties); 

供應可變參數在地圖上,像這樣:

properties.put("hibernate.connection.url", "jdbc:postgresql://127.0.0.1/test"); 
properties.put("hibernate.connection.username", "joe"); 
properties.put("hibernate.connection.password", "pass"); 
+0

你的回答是解決方案!謝謝!!。我的問題已解決 – fredicini