On Fri, 6 Feb 2004, Gus Heck wrote:

> Tried this but I am having issues....
> 
> I have an person object that holds a collection of ContactInfo. People 
> may be contacted at more than one place... etc. The contact info objects 
> are perfectly happy not knowing who they contact (they have no reference 
> to Person). This is an 1:n mapping, but the n contacts have no 
> dependancy on the 1 person. The xdoclet module seems to require that the 
> ContactInfo's all know about the Person's. This seems like a silly 
> requirement.
> 
>      From the ojbdoclet documentation:
> 
> 
> foreignkey
> 
> Contains one or more foreign key field or columns (separated by commas).
> 
> If the collection implements an 1:n association, then this attribute 
> specifies the fields in the element type that implement the association 
> on the element side. Note that these fields are required to have the 
> ojb.field
> 
>  From my class
> 
>     /**
>      * @ojb.field
>      * @ojb.collection auto-retrieve="true"
>      *                 auto-update="false"
>      *                 auto-delete="false"
>      */
>     Collection ContactsCollection;
> 
> 
>     The error:
> 
>     Generating repository_user.xml.
>     (XDocletMain.start                   53  ) Running XDoclet failed.
>     (XDocletMain.start                   54  ) <<No foreign keys
>     specified for collection ContactsCollection in type
>     org.cs101.fdb.impl.jdo.PersonBase.>>
>     build.xml [323] XDoclet failed.
>             at xdoclet.DocletTask.start(DocletTask.java:461)
>             at xjavadoc.ant.XJavadocTask.execute(XJavadocTask.java:95)
>             at
>     org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:166)
>             at org.apache.tools.ant.Task.perform(Task.java:319)
>             at org.apache.tools.ant.Target.execute(Target.java:309)
>     (the trace is about 30 miles long... I'll post it if it helps).
> 
> How do I get around this? or am I forced to put in useless, backreference?

The reference from the element object to the object with the collection is
not at all useless. It is how OJB actually implements the 1:n association
(it stores the primarykey of the object with the collection).
So basically you put in a field into the element type of the same type as
the primarykey.
There is a way to avoid this, however, by using an indirection table (as a
1:n association is a m:n association with an implicit constraint). Here
you have the foreignkeys in a separate table referencing the primarykeys
of the two ends of the association.
BTW, when you use a collection type (as opposed to an array), you have to
specify the element type, as well (using element-class-ref).

Tom


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to