users@glassfish.java.net

RE: Sematics of the orm.xml file

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Fri, 16 Jun 2006 15:37:52 -0400

Hello Vince,
   The JPA specification gives the developer the tools to configure persistence 'by exception' to fit their deployment requirements. 'by exception' means that for every annotation and XML element the specification has defined a default or a mechanism for determining defaults (eg. column names are generated by joining the field name with the pk name of the target). This means the developer need only specify the configuration that does not follow the defaults and the Persistence Provider will 'default' the rest based on the rules in the Specification.

XML and annotations can be used in many combinations. A persistence unit can have only XML and no Annotations (including @Entity) for mapping pre JDK 1.5 classes. A persistence unit can have only Annotations and no XML. An important thing to note is that XML will override annotations. This gives deployers the opportunity to tweak the persistence configuration based on the deployment target.

Overriding has 3 levels. The first and most straight-forward is per annotation overriding. When a single annotation is overridden by xml all other existing annotations and defaults continue to be used. This is usually limited to schema based changes like table names.
The next level is Entity overriding. This is when 'xml-mapping-metadata-complete' is specified on the Entity. This will cause the Persistence Provider to ignore all annotations for that Entity. Not because they are redundant but because the configuration may be different entirely. This would be used in cases where a model class is reused in a different deployment accessing an entirely different table structure.

The third level is when 'xml-mapping-metadata-complete' is specified. This will cause the Persistence Provider to ignore all annotations in the Persistence Unit. Not because they are redundant but the deployer wants to ensure that configuration is fully isolated (or controlled) by the XML file and that no annotations will 'sneak' into the Persistence Unit.

To specifically answer your questions:
1. by default the orm.xml is not a complete override, but is selective.
        - Yes

2. an orm.xml can completely override the annotations in a PU.
        - Yes

3. an orm.xml that says that it completely overrides the annotations in
a PU doesn't need to be complete....
  (that is a bit unsettling)
        - Yes, remember configuration in JPA is 'by exception'

4. an orm.xml file can completely override the annotations of a single
entity in a PU. Again, while it says it is complete,
it doesn't actually need to be....
        -Yes

--Gordon

-----Original Message-----
From: Vince.Kraemer_at_Sun.COM [mailto:Vince.Kraemer_at_Sun.COM]On Behalf Of
vince kraemer
Sent: Friday, June 16, 2006 2:09 PM
To: users_at_glassfish.dev.java.net
Subject: Re: Sematics of the orm.xml file


There be a lot of long words in there, miss. We're naught but humble
coders...

Are there any examples that illuminate this subject a bit "more"?

Is there a pointer to the spec that you are quoting from....

Thanks,
vbk

Marina Vatkina wrote:
> Hi Vince,
>
> You can choose. This is what the spec says:
>
> 10.1 XML Overriding Rules
> ...
> If the xml-mapping-metadata-complete subelement of the
> persistence-unit-metadata
> element is specified, the complete set of mapping metadata for the
> persistence unit is contained in
> the XML mapping files for the persistence unit, and annotations on the
> classes are ignored. When
> xml-mapping-metadata-complete is specified and XML elements are
> omitted, the default values
> apply[47].
Okay....

It sounds like:

1. by default the orm.xml is not a complete override, but is selective.

2. an orm.xml can completely override the annotations in a PU.

3. an orm.xml that says that it completely overrides the annotations in
a PU doesn't need to be complete....
  (that is a bit unsettling)

It seems like this implies that I can make the classes in a jar entities
by adding a persistence.xml and an orm.xml
without adding ANY annotations anywhere???
> [47] If the xml-mapping-metadata-complete element is specified, any
> metadata-complete attributes specified within
> the entity, mapped-superclass, and embeddable elements are ignored.
Because they are kind of redundant?
> ...
>
> 10.1.3.1 metadata-complete
> If the metadata-complete attribute is specified on the entity element
> itself, any annotations on
> the entity class (and its fields and properties) are ignored. When
> metadata-complete is specified
> on the entity element and XML elements are omitted, the default values
> apply to the given class.
4. an orm.xml file can completely override the annotations of a single
entity in a PU. Again, while it says it is complete,
it doesn't actually need to be....


>
> -marina
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
For additional commands, e-mail: users-help_at_glassfish.dev.java.net