Referring to artifactId from ban of maven dependency on persistence.xml

We work with JPA and try to adhere to standard specifications (and avoid Hibernate features).

We use one project (let it be called X) inside another project (A) as a dependency on Maven.

We need a JPA to scan project X for objects, and also to scan project A.

To this end, we added a line

<jar-file>lib/X-v5-4.0.jar</jar-file>

inside

<persistence-unit>

in persistence.xml. It works great.

The problem that we still have is that now we need to specify the version of project X not only in pom.xml, but also in the persistence.xml file. This is a recipe for future deployment problems.

We created a system using Maven resource filtering:

<jar-file>lib/X-v5-${x-version}.jar</jar-file>

in persistence.xml and

<properties>
  <x-version>4.0</x-version>
</properties>

and $ {x-version} in pom.xml.

, , , , X .

, pom.xml, persistence.xml. , .

?

EDIT ( ):

jpa.xml. entityManagerFactory, persistenceAnnotationBeanPostProcessor transactionManager. - entityManagerFactory bean. "packagesToScan", .

:

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="jpaDataSource" />
    <property name="loadTimeWeaver">
        <bean
            class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
    </property>
    <property name="packagesToScan">
        <list>
            <value>org.com.our.external.library.package1</value>
            <value>org.com.our.external.library.package2</value>
            <value>org.com.our.external.library.package3</value>
        </list>
    </property>
</bean>

, : , jar.

+5
2

:

persistence.xml <jar-file>, ..

<persistence-unit name="PersistenceUnit">
    ...
    <!-- here is where the jar file is supposed to go -->
    ${importjarfile}
    ...
</persistence-unit>

, :

<properties>
    <x-version>4.0</x-version>
    <importjarfile><![CDATA[<jar-file>lib/X-v5-${x-version}.jar</jar-file>]]></importjarfile>
</properties>

, Eclipse jar-file .

, .properties, CDATA, , .

:

importjarfile = <jar-file>lib/X-v5-${x-version}.jar</jar-file>
+2

unit test, , jar-file, , persistence.xml ?

persistence.xml dependency.

, dependency.version POM. , , dependency, , , , .

Maven Plugin.

0

All Articles