users@glassfish.java.net

Re: Sematics of the orm.xml file

From: vince kraemer <Vince.Kraemer_at_Sun.COM>
Date: Fri, 16 Jun 2006 14:19:36 -0700

Gordon Yorke wrote:
> 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.
>
Is there a practical example (java and xml code) that illustrates this
available somewhere?
> 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.
Is there an example (java and xml code) of this available somewhere?

by-the-by: are you referring to 'metadata-complete' here???
> 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.
An example of this?
> 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.
>
>
Thanks,
vbk