简体   繁体   English

在persistence.xml中干燥

[英]DRY in persistence.xml

I'm trying to use DRY in my persistence.xml file in different persistence units. 我试图在不同的持久性单元中的persistence.xml文件中使用DRY。 I have the following persistence.xml (it's just one file): 我有以下persistence.xml (它只是一个文件):

<persistence-unit name="siteAPU" transaction-type="JTA">
    <jta-data-source>java:/siteADS</jta-data-source> 
    <class>package.name.Subs</class>
    <class>package.name.SubsRef</class>
    <class>package.name.SubsLoc</class>
...

<persistence-unit name="siteBPU" transaction-type="JTA">  
    <jta-data-source>java:/siteBDS</jta-data-source>
    <class>package.name.Subs</class>
    <class>package.name.SubsRef</class>
    <class>package.name.SubsLoc</class>
...

You can see I have two different persistence units and I have the same classes being persisted. 您可以看到我有两个不同的持久性单元,并且有相同的类被持久化。 Is there a way I can programmatically generate the persistence.xml file and don't repeat the content inside each persistence unit? 有没有一种方法可以以编程方式生成persistence.xml文件,并且不重复每个持久性单元中的内容?

create a orm file: 创建一个orm文件:

<persistence-unit name="YOU_PU" ...>
    <provider>YOU_PROVIDER</provider>

    <mapping-file>orm.xml</mapping-file>

Inside the ORM file you will write the entities. 在ORM文件中,您将编写实体。

There is a sample here: https://github.com/uaihebert/uaicriteria/blob/master/src/test/resources/orm.xml 这里有一个示例: https : //github.com/uaihebert/uaicriteria/blob/master/src/test/resources/orm.xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM