DataNucleus - Products
  History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JAVAFIVEPLUGIN-56
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Andy Jefferson
Reporter: Chris Beams
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
JPOX Java5

JDO 2.1 : Support specification of ForeignKey, PrimaryKey within @Join, @Element, @Key, @Value annotations

Created: 26/Apr/07 10:50 PM   Updated: 17/Sep/07 09:19 AM
Component/s: JDO
Affects Version/s: 1.2.0-beta-1, 1.2.0-beta-2
Fix Version/s: 1.2.0-beta-4

Forum Thread URL: http://www.jpox.org/servlet/forum/viewthread?thread=4302


 Description  « Hide
Please read the forum thread completely when considering this issue.

Essentially, I want to have all the flexibility of the XML metadata available in JDO 2.1 annotations. Case in point, it's not possible to specify the names of foreign keys to join tables using annotations alone, e.g.:

    <field name="contacts" table="content_provider_contact">
        <collection element-type="com.example.Contact"/>
        <join>
            <primary-key name="XPKcontent_provider_contact"/>
            <column name="content_provider_id"/>
            <foreign-key name="R_4" update-action="none" delete-action="none"/>
        </join>
        <element>
            <column name="contact_id"/>
            <foreign-key name="R_5" update-action="none" delete-action="none"/>
        </element>
    </field>

This metadata informs JDO that there should be a join table called "content_provider_contact" with a primary-key called "XPKcontent_provider_contact" that is a composite of the table's two columns: "content_provider_id" and "contact_id". Additionally, there should be a foreign-key named R_5 on "contact_id" and a foreign-key named "R_4" on "content_provider_id".

The naming of the foreign-keys and primary-key are not currently possible with the current rev of JDO 2.1 annotations.

Here is my proposal for how this level of granular functionality could be supported:

    @Field(defaultFetchGroup = "true")
    @Element(column = "contact_id", foreignKey=@ForeignKey(name="R_5")
    @Join(table = "content_provider_contact", column = "content_provider_id",
          primaryKey = @PrimaryKey(name = "XPKcontent_provider_contact")
          foreignKey = @ForeignKey(name = "R_4")
    private Set<Contact> contacts = new HashSet<Contact>();

(again, see the forum thread for more detail)

Please let me know if there are further questions or more detail necessary.

Here's my overall entreaty about this: I want to be able to map any DBA-crafted schema, detail-by-detail into jdo annotations, and then be able to generate that schema identically. Using XML metadata, this is possible (at least 98% of the time, anyway). Using annotations, it's not. I propose that annotations should have the full power of JDO XML metadata. I understand it is a dubious decision to embed ORM-specific information into one's class definitions, but once that decision has been made, it should be possible to flex all of JDO's functionality with them.

At the very least, so that this bug is actionable, I'm requesting that the example snippet above be implemented with corresponding language added to the 2.1 spec:

1) Allow @Join annotations at the field level to take a single primaryKey and single foreignKey attribute.
2) Allow @Element annotations at the field level to take a single foreignKey attribute.

This meets my immediate neeeds, but I'm sure there are other cases of 'missing annotation functionality' that are desirable to get into the 2.1 timeline; if you have any such requests, please add them in separate issues and link to them here.

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Chris Beams - 26/Apr/07 10:54 PM
Created reference issue at Apache JDO project: https://issues.apache.org/jira/browse/JDO-486

Andy Jefferson - 27/Apr/07 08:24 AM
The link at Apache JDO should have been on http://issues.apache.org/jira/browse/JDO-403 - now corrected.

The only problem with this requirement is that Java5 annotations dont allow "null" default values setting so it screws up the annotation definition. We have to have a default value on the annotation or the user would have to specify those values each time they specified @Join, @Element. The ForeignKey part also applies to @Key, @Value

Chris Beams - 27/Apr/07 08:29 AM
Is there a reasonable solution/compromise to the default value problem? I'm not familiar enough with annotation design to suggest anything intelligently. Thanks for taking action on this.

Andy Jefferson - 03/May/07 09:11 PM
Reasonable solution ? Shoot the members of the JCP that approved an annotation spec that ignores null defaults and doesnt support inheritance perhaps.

The only way you can have a default for an Object type field is to have a "special" object of that type and then users of that annotation have to check for this "special" object. So in conclusion its not trivial

Andy Jefferson - 18/Jul/07 06:20 PM
JPOX now supports
1. @Element "foreignKey", "index", "unique" properties for specifying the constraint names for the element.
2. @Key "foreignKey", "index", "unique" properties for specifying the constraint names for the key.
3. @Value "foreignKey", "index", "unique" properties for specifying the constraint names for the value.
4. @Join "primaryKey" for specifying the PK constraint name for the join table

Chris Beams - 18/Jul/07 06:32 PM
Great news, thanks!