Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Spikes, FOSS JPA 1.0 test framework

Hi John,

   I took a look at your initial article and I see where you're coming from.  I liked this comment ;-) (my bolding):
So far I have been able to achieve the same effect, but in a much less brittle and disruptive fashion, for EclipseLink. Achieving the same feat with OpenJPA is proving to be a much harder task, which I'm still working on.
We've always said it was relatively easy to customize EclipseLink metadata and I'm glad you had an experience that backs that up.

One correction though, TopLink Essentials, one of the "ancestors" of EclipseLink is the JPA 1.0 reference implementation, not OpenJPA.
In terms of the problem you're addressing, things have changed since you wrote the article.
An interesting alternative, provided by JPA 1.0, is the partial metadata mapping file. In theory, you can add further, partial, mapping information in a separate XML file, which will be added to, or replace, the information already supplied by the annotations. Unfortunately, the specifications (or rather the XSD) for this metadata mapping file does not allow for vendor specific tags. I certainly haven't seen anything in the Hibernate (nor OpenJPA, and EclipseLink) manuals explaining how to add, say, Hibernate specific elements to the XML file.
Turns out that EclipseLink has a mapping file format that is compatible with the JPA orm.xml file but will support EclipseLink specific mappings.  This allows you to map your classes with only JPA 1.0 annotations in code and then augment your classes with EclipseLink specific mappings or settings.  In the example below I have a simple Entity "Title" and in the orm.xml I only specify the type of cache I want.

public class Title {
    private int id;
    <entity class="model.Publisher">
        <cache type="SOFT"/>
    <entity class="model.Title">
        <cache type="FULL"/>

You could do all this in annotations, as you point out, but if you want to keep the classes themselves fully portable then this offers a nice solution. 

The manuals for the mapping file haven't caught up with development yet but you can take a look at the functional spec and the root bug tracking this work here and here


John Leach wrote:
Dear list,
I have prepared a (very) small open source project to provide domain entity mapping and association examples, together with a programmatic interface to reach outside the JPA 1.0 specifications. Currently it works with Hibernate, EclipseLink and (almost, but not quite) OpenJPA.

The intention is to provide a 'third' alternative to annotations and/or persistence.xml, where the entity classes contain only JPA annotations, with any remaining changes being made programmatically. The one-to-many example defines CascadeType.ALL, but actually requires a 'delete-orphans' extension for the tests to succeed.

I had better warn you all that I am a freelance consultant working in Italy and I use and will be using this work to sell both the advantages and disadvantages (but with solutions) of using JPA 1.0. to my clients.

Although the EclipseLink part works, and the programmatic interface is quite simple (using the eclipselink.session.customizer property), working in a vacuum (that's me and myself, and we don't always agree) does mean that I'm never quite sure that I've found a "good enough" solution. Any help would be greatly appreciated. I am working 'in collaboration with' two Java User Groups (Torino and Trento), but it's really me who wrote most of the code.

The open source project, called Spikes (guess why) can be downloaded via Subversion with the command:

svn checkout spikes

There is a Trac site at which I have converted to English in most places, and also an article (which started the project rolling)

Best regards
John Leach, Verona, Italy

eclipselink-users mailing list


Shaun Smith | Principal Product Manager, TopLink | +1.905.502.3094
Oracle Fusion Middleware
110 Matheson Boulevard West, Suite 100
Mississauga, Ontario, Canada L5R 3P4

Back to the top