Question

I have a project setup where i have a module which is present in the WEB-INF/lib folder of the parent war file. This module contains a persistence.xml and an entity which i need to be loaded when the JPA container loads during startup. Somehow i need to merge the persistence units of the war and the lib jar. the persistence.xml of my war is present in WEB-INF/classes/META-INF hence it would take WEB-INF/classes as the persistence root and wouldnt understand the entity from my lib jar. That i found out the hard way.

I stumbled across multiple people suggesting solutions to this problem

http://ancientprogramming.blogspot.com/2007/05/multiple-persistencexml-files-and.html And i also found out that there is Spring's Data-jpa project which has a MergingPersistenceUnitManager which will merge the class definitions of the entities.

Here is my configuration

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


<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="persistenceUnitName" value="LineManagement" />
    <property name="persistenceUnitManager" ref="pum"></property>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="generateDdl" value="false" />
            <property name="showSql" value="false" />
            <property name="databasePlatform" ref="cpsHibernateDialectClassName" />
        </bean>
    </property>

which doesnt work. It gives me an error java.lang.NoSuchMethodError:org.springframework.data.jpa.support.MergingPersistenceUnitManager.getPersistenceUnitInfo(Ljava/lang/String;)Lorg/springframework/orm/jpa/persistenceunit/MutablePersistenceUnitInfo;

I have no clue how it gives me this error. From my understanding the MergingPersistenceUnitManager extends the DefaultPersistenceManager. Only thing i suspect is that there might be a conflict.

Here are my dependencies. spring-orm-3.0.2-RELEASE.jar and spring-data-jpa-1.0.3-RELEASE.jar.

I can go back to the ancient programming solution, but shouldnt it just work out of the box?

Was it helpful?

Solution

You have mismatching versions of spring-orm and spring-data-jpa. In general arbitrary versions are not guaranteed to play well together.

MutablePersistenceUnitInfo getPersistenceUnitInfo - method is absent from the MergingPersistenceUnitManager (or actually from it's superclass DefaultPersistenceUnitManager) in version orm version 3.0.2.

From same class in version 3.0.5 you can find this method: DefaultPersistenceUnitManager.java Also maven pom for spring-data-jpa-1.0.3 lists dependency to spring-orm 3.0.5. So your problem is solved by using sprin-orm version 3.0.5.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top