我在jar文件中有一个空的persistenceUnit:重写JPA持久性单元
<persistence-unit transaction-type="JTA" name="base1">
</persistence-unit>
<persistence-unit transaction-type="JTA" name="base2">
</persistence-unit>
我的想法是,在我的主要项目属性和类全persistenceUnit更换空persistenceUnit,像这样:
<persistence-unit name="base1" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/myDS</jta-data-source>
<class>br.com.myproject.MyClass</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<shared-cache-mode>NONE</shared-cache-mode>
<properties>
<property name="hibernate.hbm2ddl.auto" value="none" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="false" />
<property name="hibernate.cache.use_second_level_cache"
value="false" />
</properties>
</persistence-unit>
但是,当我尝试启动服务器,我得到了以下错误:
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYJPA0038: Falha ao adicionar o serviço da unidade de persistência para base1
Caused by: org.jboss.msc.service.DuplicateServiceException: Service jboss.persistenceunit.myproject#base1.__FIRST_PHASE__ is already registered"}}
是否有任何方法来重写persistenceUnit?
是存在的,为什么你打上一个原因JTA,看起来像资源作为非-jta数据源? – The86Freak
不,这只是一个错误,我会编辑我的文章。 – RonaldoLanhellas
你的包装做得对吗?在JAR/WAR等中没有重复的persistence.xml? 我也建议删除不需要的PU,如“base2”。 – The86Freak