usando la mergingpersistence -unitmanager per caricare l'entità
-
15-11-2019 - |
Domanda
Ho una configurazione del progetto in cui ho un modulo presente nella cartella Web-INF / Lib del file Guerra Padre. Questo modulo contiene una persistenza.xml e un'entità che devo essere caricata quando il contenitore JPA carica durante l'avvio. In qualche modo ho bisogno di unire le unità di persistenza della guerra e del jar lib. La persistence.xml della mia guerra è presente in Web-Inf / Classi / Meta-INF, prenderebbe il web-inf / lezioni come la radice della persistenza e non comprenderebbe l'entità dal mio jar di libertà libere. Che ho scoperto il modo difficile.
Mi sono imbattuto in molteplici persone che suggeriscono soluzioni a questo problema
http://cientprogramming.blogspot.com/2007/ 05 / multiple-persistenceXML-Files-and.html E ho anche scoperto che c'è il progetto DATA-JPA di primavera che ha un MergingPersistenceNetunitManager che unisce le definizioni di classe delle entità.
Ecco la mia configurazione
<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>
.
che non funziona. Mi dà un errore
java.lang.NoSuchMethodError:org.springframework.data.jpa.support.MergingPersistenceUnitManager.getPersistenceUnitInfo(Ljava/lang/String;)Lorg/springframework/orm/jpa/persistenceunit/MutablePersistenceUnitInfo;
Non ho idea di come mi dà questo errore. Dalla mia comprensione, la mergingpersistencenceunitmanager estende il defaultpersistencemanager. L'unica cosa che sospetto è che potrebbe esserci un conflitto.
Ecco le mie dipendenze. Spring-Orm-3.0.2-Release.jar e Spring-data-JPA-1.0.3-versione.jar.
Posso tornare all'antica soluzione di programmazione, ma non dovrei solo lavorare fuori dalla scatola?
Soluzione
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.