0

Is it possible to have two persistence units, one with Hibernate to work with some entities and another with EclipseLink to work with other entities in Spring framework?

manish
  • 19,695
  • 5
  • 67
  • 91
iceDice
  • 79
  • 6

1 Answers1

0

The following should work:

<bean id="schema1EM" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  ...
  <property name="jpaVendorAdapter">
    <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
      ...
    </bean>
  </property>
  <property name="packagesToScan" value="org.example.domain.schema1"/>
</bean>

<bean id="schema2EM" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  ...
  <property name="jpaVendorAdapter">
    <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
      ...
    </bean>
  </property>
  <property name="packagesToScan" value="org.example.domain.schema2"/>
</bean>

<jpa:repositories base-package="org.example.data.schema1" entity-manager-factory-ref="schema1EM"/>
<jpa:repositories base-package="org.example.data.schema2" entity-manager-factory-ref="schema2EM"/>

schema1EM will be assigned to all repositories declared under the package org.example.data.schema1 and schema2EM will be assigned to those under org.example.data.schema2. You will have to segregated the domain classes and repository interfaces by packages so that the Spring auto-wiring can work.

manish
  • 19,695
  • 5
  • 67
  • 91