cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Fredrik Liden" <fli...@translate.com>
Subject RE: Querying join table
Date Wed, 03 May 2006 20:26:12 GMT
Thanks Mike,

Adding manual object relationships, is this for creating the flattend
relationships only? Actually I don't want to flatten it because I have a
few more fields in the join table (that I didn't include).

However for some reason I can't use this:
survey.addToToAssignments(person_survey);
person.addToToAssignments(person_survey);

I get some commit error and it seems it's trying to generate a PK for
the join table. So I used the code I found in the mailing list:

Person_Survey person_survey =
(Person_Survey)context.createAndRegisterNewObject(Person_Survey.class);
person_survey.setToOneTarget("toSurvey", survey, false);
person_survey.setToOneTarget("toPerson", person, false);

This seems to add it to the join table, however it doesn't seem to
update the reverse relationships. Not 100 percent here.

The "to dep PK" should be checked in the PERSON_SURVEY table right and
not in the SURVEY and PERSON tables right? Any ideas why the top code
doesn't work?


-----Original Message-----
From: Mike Kienenberger [mailto:mkienenb@gmail.com] 
Sent: Wednesday, May 03, 2006 11:07 AM
To: cayenne-user@incubator.apache.org
Subject: Re: Querying join table

On 5/3/06, Fredrik Liden <fliden@translate.com> wrote:
> I'm trying to figure out two queries from the following structure.
>
> SURVEY
> SurveyID  (PK)
>
> PERSON_SURVEY
> PersonID (PK,FK)
> SurveyID (PK,FK)
>
> PERSON
> PersonID (PK)
>
>
> 1. I have a join table PERSON_SURVEY with a composite key of PersonID
> and SurveyID. How can I query for all the entries where PersonID =
> 'something'. Do I use an expression or a path? Since this is a
composite
> key and is part of the PK. In general, is it preferred to stay away
from
> composite keys in the join tables?

Yes, I recommend using a composite join table.   Cayenne has excellent
support for this situation.  Make sure to mark the reverse
DbRelationships as "to dep key".   You'll probably need to manually
add ObjRelationships to your Person and Survey ObjEntities.

Once you've configured everything correctly, your join tables will be
invisible to your application.   You'll be able to use
person.addToSurveyList() and person.getSurveyList() and
survey.addToPersonList() and survey.getPersonList() transparently.

Mime
View raw message