如何在OpenJPA中覆盖persistence.xml属性
发布时间:2020-12-16 23:05:39 所属栏目:百科 来源:网络整理
导读:我的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,idleConnec
我的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,idleConnectionTestPeriod=60 但它不起作用:OpenJPA总是从persistence.xml读取属性值 仅当删除persistence.xml中的属性时,它才会从系统属性中读取值. 这是预期的行为,如果是这样,从persistence.xml覆盖属性的正确方法是什么? 解决方法
创建EM / EMF时,OpenJPA默认不查看SystemProperties.在创建EMF时尝试传入System.getProperties().
Persistence.createEntityManagerFactory(“pu_Name”,System.getProperties()); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |