开发者

Combine two or more persistence.xml(s) into one, when packaging (war) many modules (Maven)

开发者 https://www.devze.com 2023-01-02 18:48 出处:网络
I have a maven-managed 开发者_如何学Pythonproject with some modules (with jar package). Each module contains its "persistence.xml" file in its META-INF directory.

I have a maven-managed 开发者_如何学Pythonproject with some modules (with jar package). Each module contains its "persistence.xml" file in its META-INF directory.

Another module has the responsibility to package these modules into a war file. But I have not found a way to "combine" these "persistence.xml" files into a single file.

Is it possible?


If you know XSLT, you can write a transform to merge the persistence documents. Maven has a plugin for running XSLT (and validationg XML) - xml-maven-plugin

But do you need to do this? Reading here, and here, for example, states that persistence.xml will be picked up from all jars, not just the webapp war. So you should be able to leave persistence.xml in your library jars and the will be used by the webapp.


hi in order to let the server searching for multiple persistence.xml files and configure all persistence units, you have to package this persistence.xml file on EJB JAR file.

Aymen


Another module take responsibilities to package these modules into a war file . But I find no way to "combine" these "persistence.xml" into one file

Why would you like to do this? If you have several JARs that have a persistence.xml, they define very likely different persistence units (A persistence unit defines the set of all classes that are related or grouped by the application and which must be colocated in their mapping to a single database).

Why don't you obtain an EntityManagerFactory for the right persistence unit?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号