db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Jefferson <a...@jpox.org>
Subject MetaData : XML .v. Annotation precedence - primary-key
Date Fri, 10 Aug 2007 07:55:16 GMT
I came across a particular situation that impacts on the wording for the text 
to go in the spec for precedence of XML and Annotation metadata.

I have :-

@PersistenceCapable
public class MyClass
{
    @PrimaryKey
    long id;

    @Persistent
    String name;

    ...
}

Question : Should we allow users to override the setting of "primary-key" in 
XML when it is defined in the annotations ? or should the setting in the 
annotations for which field(s) are PK be fixed ?

The problem comes in how to merge the value in annotations and value in XML. 
With XML, due to the DTD/XSD, there will always be a value for "primary-key". 
With annotations it will have a value only if the user provided one.

If we allow overrides via XML, then we must just take any value from XML 
(since there is always a value when read in). This impacts on what a user has 
to specify when overriding any information in XML. For example, if the user 
wanted to override some info about the above class they would have to specify 
the "primary-key" values correctly to make sure that they were respected (if 
they didn't specify the "primary-key" element then they get the DTD default 
of "false"!) hence duplicate definition.


My conclusion is that we should prohibit the override of "primary-key" when 
the annotations have explicitly set the value. If annotations haven't set the 
value then the value in XML should be respected. 
Anyone disagree ?


-- 
Andy  (Java Persistent Objects - http://www.jpox.org)

Mime
View raw message