DRY in persistence.xml

60 Views Asked by At

I'm trying to use DRY in my persistence.xml file in different persistence units. I have the following persistence.xml (it's just one file):

<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?

1

There are 1 best solutions below

3
On BEST ANSWER

create a orm file:

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

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

Inside the ORM file you will write the entities.

There is a sample here: https://github.com/uaihebert/uaicriteria/blob/master/src/test/resources/orm.xml