Using MergingPersistenceUnitManager to load an object

I have a project setup where I have a module that is present in the WEB-INF / lib folder of the parent war file. This module contains the persistence.xml file and the object that needs to be loaded when the JPA container is loaded at startup. Somehow I need to combine the war persistence units and the lib bank. The persistence.xml of my war is present in WEB-INF / classes / META-INF, so WEB-INF / classes will be required as the persistence root and it will not be able to understand the entity from my jb library. That I discovered the hard way.

I came across several people offering solutions to this problem

http://ancientprogramming.blogspot.com/2007/05/multiple-persistencexml-files-and.html And I also found out that there is a Spring Data-jpa project that has a MergingPersistenceUnitManager that combines object class definitions.

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 does not work. This gives me the error java.lang.NoSuchMethodError:org.springframework.data.jpa.support.MergingPersistenceUnitManager.getPersistenceUnitInfo(Ljava/lang/String;)Lorg/springframework/orm/jpa/persistenceunit/MutablePersistenceUnitInfo;

I have no idea how this gives me this error. In my opinion, MergingPersistenceUnitManager extends DefaultPersistenceManager. The only thing I suspect is conflict.

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

I can return to the ancient software solution, but should it not work out of the box?

+2
source share
1 answer

You have inappropriate versions of spring -orm and spring -data-jpa. In general, custom versions are not guaranteed to fit well.

MutablePersistenceUnitInfo getPersistenceUnitInfo - the method is missing in the MergingPersistenceUnitManager (or in fact from it the superclass DefaultPersistenceUnitManager) in orm version 3.0.2.

From the same class in version 3.0.5 you can find this method: DefaultPersistenceUnitManager.java Also maven pom for spring -data-jpa-1.0.3 indicates dependency on spring -orm 3.0.5. So, your problem is solved with sprin-orm version 3.0.5.

+1
source

Source: https://habr.com/ru/post/909668/


All Articles