3
我在META-INF /文件夾中的persistence.xml後創建實體管理器工廠:如何修改屬性從persistence.xml中
<persistence-unit name="dev" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/events" />
<property name="javax.persistence.jdbc.user" value="postgres" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
在Java代碼中我從persistence.xml中
創建實體管理器製造工廠_emf = Persistence.createEntityManagerFactory("dev");
_em = _emf.createEntityManager();
但是我想爲測試做動態變化只有JDBC URL /用戶/密碼,我的計劃是,以保存這些參數在配置文件,並根據需要閱讀,那麼有沒有一種方法,我可以以後更新它們我從persistence.xml創建entitymanagerfactory?所以它會是這樣的:
_emf = Persistence.createEntityManagerFactory("dev");
_emf.setProperties("url", "test_url");
... other setts here ...
_em = _emf.createEntityManager();
感謝