db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig L Russell <Craig.Russ...@Sun.COM>
Subject [DISCUSS] Nested embedded annotation
Date Fri, 29 Jun 2007 17:33:57 GMT
An objective of JDO annotations is to be as expressive as xml  
metadata. To that end, we should allow for nested embedded. Here's  
the use case:

class Address {
String description;
Coordinates location;
}
class Coordinates {
double latitude;
double longitude;
}
class Employee {
String name;
Address address;
}

TABLE EMPLOYEE (
NAME VARCHAR(255),
DESCRIPTION VARCHAR(255),
LATITUDE DOUBLE,
LONGITUDE DOUBLE)

<class name="Employee" table="EMPLOYEE">
   <field name="name" column="NAME"/>
   <field name="address">
     <embedded>
       <field name="description" column="DESCRIPTION"/>
       <field name="location">
         <embedded>
           <field name="latitude" column="LATITUDE"/>
           <field name="longitude" column="LONGITUDE"/>
         </embedded>
       </field>
     </embedded>
   </field>
</class>

I'd like to add an embedded element to @Field of type @Embedded[ ]  
but annotations cannot contain cyclic references.

As an alternative, we can flatten the nested embedded fields like this:

class Employee {
@Column(name="NAME")
String name;
@Embedded(nullIndicatorColumn="DESCRIPTION",
   fields={
     @Field(name="address.description", columns=@Column 
(name="DESCRIPTION")),
     @Field(name="address.location.latitude", columns=@Column 
(name="LATITUDE")),
     @Field(name="address.location.longitude", columns=@Column 
(name="LONGITUDE"))})
Address address;
}

We still need a way to annotate a nested embedded null indicator  
column. In the above example, Address might have a description but  
null location. To do this, we can add a nullIndicatorColumn to the  
@Field annotation, e.g.

     @Field(name="address.location", nullIndicatorColumn="LATITUDE")

Summary of proposed changes:

1. Add element name() to @Field to name the fields of the embedded  
mapping.
2. Allow dotted notation for field names for nested embedded.
3. Add element nullIndicatorColumn to @Field to identify nested  
embedded null indicator.

Craig

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Mime
View raw message