[英]How do I specify the persistence unit name to be used in the generated persistence.xml?
我們廣泛使用Hyperjaxb3(版本0.6.2)來創建和定制JPA實體類。
一個小煩人的事實是,當我們添加到架構中時,生成的持久性單元名稱有時會更改。 特別是,當我們1)更改包含的XSD文件中的XML名稱空間,2)從編譯中刪除名稱空間或3)將名稱空間添加到編譯中時,就會發生這種情況。
看起來,generate名稱空間是編譯中包含的(massaged)名稱空間的串聯,因此有意義的是,如果我們調整名稱空間,則生成的單元名稱將更改。
問題是,我們需要在幾個模塊中的一些其他配置文件中包含持久性單元名稱。 每次持久性單元名稱更改時,我們都有更多文件要更新。
我們希望能夠在調用xjc時(在我們的maven構建中)或在全局綁定中指定持久性單元名稱。
如何指定在生成的persistence.xml中使用的持久性單元名稱?
我們尚未找到解決此問題的真正方法。 在我們這樣做之前,我們將使用以下解決方法。
在我們的pom.xml中,在生成xjc代碼之后,我們將進行后期處理以替換生成的persistence.xml中的持久性單元名稱。 在此示例中,我們基於Maven模塊名稱命名持久性單元。
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<executions>
<execution>
<id>Name Persistence Unit</id>
<phase>process-resources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<includes>
<include>${basedir}/target/generated-sources/xjc/**/persistence.xml</include>
</includes>
<regex>true</regex>
<replacements>
<replacement>
<token>persistence-unit name=".*"</token>
<value>persistence-unit name="${project.artifactId}"</value>
</replacement>
</replacements>
</configuration>
</execution>
</executions>
</plugin>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.