且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从persistence.xml创建实体管理器工厂后如何修改属性

更新时间:2023-01-15 08:32:53

创建EntityManagerFactory时,可以传递一组属性,这些属性将覆盖persistence.xml中定义的属性,例如:

When you create the EntityManagerFactory, you can pass a set of properties that will override what is defined in persistence.xml, e.g.:

Properties props = new Properties();
props.setProperty("javax.persistence.jdbc.url", "test_url");
_emf = Persistence.createEntityManagerFactory("dev", props);

如果要在创建EntityManagerFactory之后修改连接属性,则必须通过再次调用createEntityManagerFactory()重新创建它.

If you want to modify the connection properties after the EntityManagerFactory was created, you must recreate it by calling createEntityManagerFactory() again.