Hi Patrice,
Thanks for mentioning those other possibilities. I'll try to expand on
the points that you've raised. If you have any more TOPLink specific
questions you can always contact us directly (the EJB list may not
want all this discussion...).
>Could you please comment below about the two alternatives mentioned
>in the TOPLink Builder documentation for implementing a one-to-many
>relationship ?
>The TOPLink Builder documentation says :
>Alternatives to the one-to-one mapping back reference include:
>- use a direct-to-field mapping to map the foreign key and maintain
>its value in the application. Here the object model does not require a
>back reference, but the data model still requires a foreign key in the
>target table.
>- use a many-to-many mapping to implement a logical one-to-many.
>This has the advantage of not requiring a back reference in the object
>model and not requiring a foreign key in the data model. In this model
>the many-to-many relation table stores the collection. It is possible to
>put a constraint on the join table to enforce that the relation is a
>logical one-to-many relationship.
>- alternative 1 : could you explain "use a direct-to-field
>mapping to map the foreign key and maintain its value in the
>application" ?
If you store the foreign key at the application level by making it
an explicit part of your object model, you can always execute a query
or finder using this information when you want to traverse the relationship.
For example a Person has many Cars. If ownerId is made an explicit field in
the Car object, then you can create a query/finder "findByOwnerId()".
When you want the Cars for a given person, you would execute this query.
Essentially, mapping the foreign key as a "direct to field" and putting
it in the object model makes it queryable. (If you didn't make the foreign
key part of the object, you could still build a TOPLink query to resolve
the relationship, but it might be more confusing to someone looking at
your code.)
>- alternative 2 : could you explain "It is possible to put a
>constraint on the join table to enforce that the relation is a logical
>one-to-many relationship" ?
Using the above example with Person and Car, your join table would have
two columns PersonId and CarId. You could put a uniqueness constraint on
the PersonId column. This would effectively enforce a 1-n relationship
between Persons and Cars.
I hope this helps.
Regards,
Dan MacKinnon
The Object People
http://www.objectpeople.com
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".