其他分享
首页 > 其他分享> > 如何在OpenJPA中覆盖persistence.xml属性

如何在OpenJPA中覆盖persistence.xml属性

作者:互联网

我的persistence.xml中有以下属性:

<property name="openjpa.ConnectionProperties"
value="DriverClassName=com.mysql.jdbc.Driver,jdbcUrl=jdbc:mysql://localhost:3306/c,user=foo,password=foo,autocommit=false,automaticTestTable=testtable,idleConnectionTestPeriod=60"/>

我试图使用系统属性覆盖它,根据docs,所以我设置:

-Dopenjpa.ConnectionProperties=DriverClassName=com.mysql.jdbc.Driver,jdbcUrl=jdbc:mysql://localhost:3306/bar,user=bar,password=bar,autocommit=false,automaticTestTable=testtable,idleConnectionTestPeriod=60

但它不起作用:OpenJPA总是从persistence.xml读取属性值

仅当删除persistence.xml中的属性时,它才会从系统属性中读取值.

这是预期的行为,如果是这样,从persistence.xml覆盖属性的正确方法是什么?

解决方法:

创建EM / EMF时,OpenJPA默认不查看SystemProperties.在创建EMF时尝试传入System.getProperties().

Persistence.createEntityManagerFactory(“pu_Name”,System.getProperties());

标签:java,jpa,openjpa
来源: https://codeday.me/bug/20190531/1187610.html