Announcement Announcement Module
Collapse
No announcement yet.
Merging multiple persistence.xml is working for Spring 2 not working for Spring 3.1 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Merging multiple persistence.xml is working for Spring 2 not working for Spring 3.1

    I have requirement of using multiple persistence.xml file in more than one module (jars) inside a web application (war). I need to merge all the persistence.xml file with the same persistence context name("default") and create and use the EntityManager out of them. I used 'MergePersistenceUnitManager.java' code. It was working for spring 2, but not working for spring 3.1

    It gives error - "Conflicting persistence unit definitions for name 'default'"

    This issue is caused because of code change for 'DefaultPersistenceUnitManager.java' in springframework 3.1 ie.

    if (!this.persistenceUnitInfoNames.add(name)) {
    StringBuilder msg = new StringBuilder();
    msg.append("Conflicting persistence unit definitions for name '").append(name).append("': ");
    msg.append(pui.getPersistenceUnitRootUrl()).append (", ");
    msg.append(this.persistenceUnitInfos.get(name).get PersistenceUnitRootUrl());
    throw new IllegalStateException(msg.toString());
    }


    Please help me to solve this issue. It is urgent.

  • #2
    packagesToScan

    Hi, i had the same problem switching to 3.1.

    using the packagesToScan property instead of using persistance.xml and a PersistanceUnitManager solved my Problems.

    Comment


    • #3
      The biggest issue with that is that it forces you to push all of your definitions into the same xml file. If you have multiple modules each defining their own persistence.xml, you're pretty much hosed until 3.1.1.

      Comment


      • #4
        It seems you're stuck with [0, 1]. We already have a fix from our side in place with 1.0.3.RELEASE of Spring Data JPA but have to wait for Spring 3.1.1 to be released. It's scheduled for next week so it shouldn't be too far away .

        [0] https://jira.springsource.org/browse/DATAJPA-138
        [1] https://jira.springsource.org/browse/SPR-8925

        Comment


        • #5
          Originally posted by Oliver Gierke View Post
          It seems you're stuck with [0, 1]. We already have a fix from our side in place with 1.0.3.RELEASE of Spring Data JPA but have to wait for Spring 3.1.1 to be released. It's scheduled for next week so it shouldn't be too far away .

          [0] https://jira.springsource.org/browse/DATAJPA-138
          [1] https://jira.springsource.org/browse/SPR-8925
          Yay! Finally the nightmare is almost over. Not sure how that didn't get caught in a unit test though

          Comment


          • #6
            same isse

            I am using spring 3.1.1 and I got still the issue :
            Conflicting persistence unit definitions for name 'default'

            I have several persistence unit file having different name, in each one the persistence unit name is "default".
            If I set a persistence unit name different, I got this error :
            No persistence unit with name 'default' found

            below my spring config file :
            <bean id="pum" class="org.springframework.orm.jpa.persistenceunit .DefaultPersistenceUnitManager">
            <property name="persistenceXmlLocations">
            <list>
            <value>classpath*:META-INF/persistence-1.xml</value>
            <value>classpath*:META-INF/persistence-2.xml</value>
            </list>
            </property>
            </bean>
            <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
            <property name="persistenceUnitManager" ref="pum" />
            <property name="dataSource" ref="dataSource" />
            <property name="jpaVendorAdapter" ref="openJpaVendorAdapter" />
            </bean>

            Please Help !
            Last edited by BBeguin; Dec 11th, 2012, 12:04 PM.

            Comment

            Working...
            X