0

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?

SaintLike
  • 9,119
  • 11
  • 39
  • 69

1 Answers1

1

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

uaiHebert
  • 1,882
  • 11
  • 21
  • 1
    Add them to the orm.xml. Just write it once and it will be ok. – uaiHebert Dec 01 '14 at 15:51
  • What about properties? Can I add them to the orm.xml? – SaintLike Dec 01 '14 at 17:09
  • 1
    I think that it is not possible to pass properties in the orm file. You could create the entity manager factory manually e pass the properties like: ``Persistence.createEntityManagerFactory("your_persistence unit", yourPropertyMap)`` – uaiHebert Dec 01 '14 at 17:12