persistence@glassfish.java.net

Single persistence unit spread over multiple files

From: Martin Bayly <mbayly_at_telus.net>
Date: Thu, 28 Dec 2006 15:32:56 -0800

Is it supported to have a single persistence unit spread over multiple
persistence xml files?

The background behind this question is that we have a modular app where
each module contributes some persistent entities.
I would like to define a persistence.xml file for each module and have
them all 'contribute' to a single common persistence unit at runtime.

i.e. one module's xml file would contain:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
    <persistence-unit name="pu1">
        
<provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>

        <class>com.mydomain.domain.Course</class>

    </persistence-unit>
</persistence>

And another module's persistence.xml file might contain

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
    <persistence-unit name="pu1">
        
<provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>

        <class>com.mydomain.domain.User</class>

    </persistence-unit>
</persistence>


Thanks
Martin