persistence@glassfish.java.net

Re: Extending the persistence unit

From: Sahoo <Sahoo_at_Sun.COM>
Date: Wed, 03 Oct 2007 23:35:55 +0530

The spec can be modified to accommodate multiple mapping files by same
name. The 2.0 spec effort has just begun, you can send your comments to
the EG.

Thanks,
Sahoo

Aleksei Valikov wrote:
> 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
>