persistence@glassfish.java.net

Re: Extending the persistence unit

From: Aleksei Valikov <aleksei.valikov_at_gmail.com>
Date: Wed, 3 Oct 2007 19:47:03 +0200

Hi.

> Entity listener information can be supplied in O/R mapping XML file like
> orm.xml. You can have a provision for a mapping file in your
> persistence.xml file by adding a <mapping-file> entry in
> persistence.xml of base-project.jar. You can populate the content of
> that mapping file as per your need and install it in classpath. If you
> don't want any listeners, just install a valid, empty mapping file.
> Again, take a look at the spec for more details about mapping file.

This is the approach I was also thinking of. The drawback is that
implementing this will make base-project.jar non-functional.

Consider we have

    <persistence-unit name="myUnit">
        <!-- The mapping file -->
        <mapping-file>org/jvnet/hyperjaxb3/ejb/tests/po/orm.xml</mapping-file>
        <!-- Some classes -->
        <class>org.jvnet.hyperjaxb3.ejb.tests.po.Items</class>
        <class>org.jvnet.hyperjaxb3.ejb.tests.po.USAddress</class>
        <class>org.jvnet.hyperjaxb3.ejb.tests.po.PurchaseOrderType</class>
        <class>org.jvnet.hyperjaxb3.ejb.tests.po.Items$Item</class>
    </persistence-unit>
</persistence>


1) If we don't have the org/jvnet/hyperjaxb3/ejb/tests/po/orm.xml file
in the base-project, this will fail since no appropriate resource
could be found.
2) Id we do have the org/jvnet/hyperjaxb3/ejb/tests/po/orm.xml file
(empty) in the base project, then base-project.jar on its own will not
fail.
However if we add extended-project.jar also containing the
org/jvnet/hyperjaxb3/ejb/tests/po/orm.xml, then which of these
resources (from the base-project.jar or the extended-project.jar) will
be loaded is non-determenistic.

Yes you could surely alway carry base-project.jar with
empty-project.jar containing an empty
org/jvnet/hyperjaxb3/ejb/tests/po/orm.xml resource, but it's kinda
weird.

Bye.
/lexi