[英]multiple database with JPA Hibernate without Spring
我有一個不帶Spring的JPA Hibernate應用程序,我需要連接到多個數據庫(具有相同的estructure)。
將為每個客戶端創建數據庫,並且必須使用相同的實體管理器。 請我對如何做到這一點有一些想法。 我沒有使用Spring。 我的應用程序使用MySql,JPA2,Hibernate和JSF。
謝謝!
如果除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");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.