openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject RE: XML overrides annotations, except when it doesn't
Date Wed, 30 Dec 2009 20:02:00 GMT
> -----Original Message-----
> Sent: Wednesday, December 30, 2009 10:58 AM
> To:
> Subject: RE: XML overrides annotations, except when it doesn't
> > -----Original Message-----
> > Sent: Tuesday, December 29, 2009 9:05 AM
> > To:
> > Subject: XML overrides annotations, except when it doesn't
> >
> > Both the JPA spec and the OpenJPA doc implies that if I have
> > annotations
> > on a field and a definition for the field in my orm.xml file, the
> > annotations for that field will be ignored and only the XML
> definition
> > will be used.  Is that correct?
> >
> > I believe I've found a situation where that isn't exactly true, and
> I'd
> > like to understand whether this is a bug or a misunderstanding.
> I'd really like to get some clarification on this point.  I've
> discovered a "feature" related to this that I like, and I'd like to
> know
> whether I can depend on it.
> As I said, the spec implies that the XML overriding is on a "field"
> basis, so that if you have anything specified for a field in the XML,
> it
> should override anything in the annotations for that field.  OpenJPA
> appears to be using a more "fine-grained" approach, instead of what
> spec says.  For instance, if I have an enum type where the XML
> specifies
> the column name, but the annotations for the field do not, and the
> annotations specify the OpenJPA-specific "Strategy" annotation, this
> essentially "merges" the annotations with the XML, so that everything
> works.
> Similarly, if I have a OneToMany and I want to use the "OrderColumn"
> annotation (I'm not using the 2.0 implementation), I appear to be able
> to use the "OrderColumn" annotation even if I have the XML for the
> field
> specifying the column.

Sigh.  I spoke too soon.  The "OrderColumn" annotation is "merged", but
not the "Strategy" annotation.  I have two fields, one using
"OrderColumn" and the other using "Strategy".  Both have XML definitions
for the fields.  I'm finding that the "OrderColumn" setting is being
observed, but not the "Strategy" setting.

If I then comment out the XML definition for the fields that use
"Strategy", but not the ones that use "OrderColumn", my Strategy works,
and so does my list ordering.

I guess I can now conclude there is a bug here, as I've determined the
treatment is inconsistent, but I don't know which one is wrong.

> I like this "fine-grained" approach, as it's really more logical and
> functional.  However, if I'm understanding the spec, this isn't
> portable
> to another JPA implementation.  I hope I'm wrong.
> > I prefer to define "logical" annotations and "physical" XML.  This
> > effectively means that many annotations would be ignored, but I like
> > seeing the logical relationships defined in the entity class.
> >
> > I have numerous "OneToMany" annotations defined in my entities, with
> > the
> > corresponding physical XML.  What I accidentally discovered is that
> > had some entities where I had added "(fetch = FetchType.EAGER)" to
> the
> > annotation, but I never added the corresponding setting to the XML.
> I
> > found those relationships were being eagerly fetched.  When I tried
> > removing the "fetch" setting in the annotation, the relationship
> became
> > lazily fetched.  So, although the docs say that the overriding is at
> > the
> > "field" level, and not the "piece of a field" level, it appears that
> > the
> > settings in the annotation and the XML have been "merged" in some
> way.
> >
> > Is the "fetch" setting an exception to the rule as I understand it?
> > Are
> > there other exceptions to this?  Is this a bug, according to the
> spec?

View raw message