When I was re-defining one of my objects last night, the orm.xml was
invalidated on a ManyToOne relationship I had in an Embeddable. Now the
curious thing about this, is the annotation on the bean had previously
been in place for near a year (through using Hibernate, then Toplink and
now EclipseLink). I took a look at the persistence orm XML definition and
sure enough the error was correct... only BASIC and TRANSIENT are allowed.
So which is correct? The orm preventing this, or the annotations allowing
this?
Well the answer depends on your definition of 'correct'. The
specification does not allow relationship mappings within an Embeddable
but EclipseLink does. As the XSD is restrictive in nature and the XSD is
defined by the specification the validation error results. Annotations
definitions are not as restrictive and as EclipseLink supports
relationship mappings within an Embeddable the annotations are
successfully processed. This is the best compromise between functionality
and compliance.
--Gordon
The JPA 1.0 spec does not allow any relationships in Embeddables.
EclipseLink does support this (as well as nested embeddables and
inheritance).
You can either,
- use the eclipselink-orm.xml instead of the JPA orm.xml
- keep using the annotation
- define the mapping using a DescriptorCustomizer
- or move it up from the embeddable to the parent