Results 1 to 6 of 6

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

  1. #1
    Join Date
    Feb 2012
    Posts
    2

    Question 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. #2
    Join Date
    Feb 2007
    Location
    Berlin, Germany
    Posts
    5

    Default 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.

  3. #3

    Default

    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.

  4. #4
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    492

    Default

    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

  5. #5

    Default

    Quote 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

  6. #6
    Join Date
    Dec 2012
    Posts
    2

    Default 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 at 11:04 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •