使用JBPM,spring,JPA(Hibernate)在tomee中部署多个peristence.xml时出现问题

时间:2016-07-18 04:17:18

标签: spring hibernate jpa persistence jbpm

我在通过persistence.xml配置多个xml configuration多个实体管理器时遇到问题,有人可以帮我解决配置问题。     问题:

  

SEVERE [main] org.apache.openejb.config.ReportValidationResults.logResults FAIL ... core-web-1.0_A0:@PersistenceContext unitName required,多个单位可用:ref" em",可用单位[applicationPersistenceUnit,applicationPersistenceUnit,applicationPersistenceUnit,applicationPersistenceUnit]

Below is configuration:

    <bean id="appEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" p:jpadialect-ref="jpaDialect" p:jpavendoradapter-ref="jpaVendorAdapter">
<property name="jpaProperties"/>
<property name="packagesToScan">
<list>
<value>${application.model.packagesToScan}</value>
<value>org.kie.*</value>
<value>org.jbpm.*</value>
</list>
</property>
<property name="dataSource" ref="appDataSource"/>
<property name="persistenceUnitManager" ref="persistenceUnitManager"/>
</bean>

<bean id="persistenceUnitManager" class="org.springframework.data.jpa.support.MergingPersistenceUnitManager">
<property name="persistenceXmlLocations">
<list>
<value>classpath*:META-INF/persistence.xml</value>
<value>classpath*:META-INF/workflow-persistence.xml</value>
</list>
</property>
<property name="defaultDataSource" ref="appDataSource"/>
</bean>

有多个persistence.xmls的原因是JBPM需要单独的一组类。

2 个答案:

答案 0 :(得分:0)

似乎你有多个持久性单元,但是jpa不知道如何处理实体管理器。哪个持久性单元应该属于哪个?

尝试这样(相应地改变你的本地需求)

  @PersistenceContext(unitName = "UNIT1", type = PersistenceContextType.TRANSACTION)
  private EntityManager unit1EntityManager;

  @PersistenceContext(unitName = "UNIT2", type = PersistenceContextType.TRANSACTION)
  private EntityManager unit2EntityManager;

  @PersistenceContext(unitName = "UNIT3", type = PersistenceContextType.TRANSACTION)
  private EntityManager unit3EntityManager;

答案 1 :(得分:0)

如果您有一些非EE(100%弹簧,独立或其他)的罐子,您可以将它们从扫描中排除,创建一个WEB-INF / exclusions.list并在里面添加:

default-list
myjarprefix

如果jar被命名为myjarprefix-1.2.3.jar,例如。

它会阻止没有名称的EE @ PersistenceContext / @ PersistenceUnit被扫描,因此会让容器启动。

如果类与EE代码混合,您可以添加WEB-INF / scan.xml:

<scan>
    <packages>
      <package>com.company.application.myeepackage</package>
    </packages>
</scan>

注意不要列出包含您要排除的类的包