Hi Charles,

Thanks for the detailed answer.  That does the job nicely.  We had moved
from an m:n relationship and were somewhat blinded by the fact that we
hadn't been using the association table directly (we had used it as an
'indirection-table').

Thanks again,
John


-----Original Message-----
From: Charles Anthony [mailto:[EMAIL PROTECTED]
Sent: 04 March 2003 16:46
To: 'OJB Users List'
Subject: RE: Ternary associations


Hi,

OK, I think I understand what you want.

Why is this a "special" scenario ?

You can (and we have in our app) defined a class that represents the
relationship. We have mapped that to a table with the corresponding ids. We
can then do queries/updates on that relationship as with any other.

Here's an example : it's worked entirely in the email and is probably too
brief, so it doesn't compile and probably has errors. However, it should
illustrate that it is possible with OJB.

java class :

public class ProjectRelationship {
  Integer developerId;
  Integer languageId;
  Integer projectId;
  
  Developer developer;  
  Language lanuage;
  Project project;
/** Normal setters and getters **/
}

extract from the repository :

<class-descriptor class="ProjectRelationship" table="PROJECTRELATIONSHIP">
  <field-descriptor id="1" name="developerId" column="DEVELOPER_ID"
jdbc-type="INTEGER" />
  <field-descriptor id="2" name="languageId" column="LANGUAGE_ID"
jdbc-type="INTEGER" />
  <field-descriptor id="3" name="projectId" column="PROJECT_ID"
jdbc-type="INTEGER" />
  <reference-descriptor name="developer" class-ref="Developer">
    <foreignkey field-id-ref="1" />
  </reference-descriptor>
  <reference-descriptor name="language" class-ref="Language">
    <foreignkey field-id-ref="2" />
  </reference-descriptor>
  <reference-descriptor name="project" class-ref="Project">
    <foreignkey field-id-ref="3" />
  </reference-descriptor>
</class-descriptor>

storing a relationship :

Developer d = .... (create or retrieve);
Project p = .... (create or retrieve);
Language l = .... (create or retrieve);
ProjectRelationship r = new ProjectRelationship();
r.setDeveloper(dev);
r.setLanguage(l);
r.setProject(p);

Broker.store(r);

querying for all relationships that developer 'bob' has in 'java' :
Criteria criteria = new Criteria();
criteria.addEqualTo("developer.name","bob");
cirteria.addEquatTo("language.name","java");

Query q = new QueryByCriteria(ProjectRelationship.class, criteria, true);
Collection relationships = Broker.getCollectionByQuery(q);

You can then iterate through the relationships to get the projects.

You could also have on the Project class-descriptor a
<collection-descriptor> that returns all relationships associated with the
Project. If it was call "projectRelationships" the following would give you
all projects that have a relationship with "bob" and the language "java".

Criteria criteria = new Criteria();
criteria.addEqualTo("projectRelationships.developer.name","bob");
cirteria.addEquatTo("projectRelationships.language.name","java");

Query q = new QueryByCriteria(Project.class, criteria, true);
Collection projects = Broker.getCollectionByQuery(q);

Hope that helps ,

Cheers,

Charles.

>-----Original Message-----
>From: O'Reilly John [mailto:[EMAIL PROTECTED]
>Sent: 04 March 2003 16:22
>To: 'OJB Users List'
>Subject: RE: Ternary associations
>
>
>Hi,
>
>With a ternary relationship there are three (or more) objects 
>'related' to
>each other.  An example would be 'developer', 'language', 
>'project'.  You
>want to represent the combinations of these that exist.  It's 
>realised by a
>bridge table with 3 columns representing the foreign keys in 
>the other 3
>tables (just like an m:n association is represented by a table with 2
>columns).
>
>The following explains how hibernate supports ternary associations.
>http://www.xylax.net/hibernate/ternary.html
>
>Regards,
>John
>
>-----Original Message-----
>From: Charles Anthony [mailto:[EMAIL PROTECTED]
>Sent: 04 March 2003 16:08
>To: 'OJB Users List'
>Subject: RE: Ternary associations
>
>
>I didn't know exactly what a Ternary association is. 
>A quick google suggests that it is what OJB calls an M:N association (a
>resolution for a many-many relationship).
>
>If it is one of them, then yes, OJB does support it.
>
>See 
>http://db.apache.org/ojb/tutorial3.html#mapping%20m:n%20associations
>
>Cheers,
>
>Charles.
>
>>-----Original Message-----
>>From: O'Reilly John [mailto:[EMAIL PROTECTED]
>>Sent: 04 March 2003 15:58
>>To: 'OJB Users List'
>>Subject: RE: Ternary associations
>>
>>
>>Hi,
>>
>>Sorry to repost the following question but can someone give 
>me a yes/no
>>answer on this.  If no, then we need to look for another way 
>>of doing this.
>>
>>Thanks,
>>John
>>
>>
>>-----Original Message-----
>>From: O'Reilly John [mailto:[EMAIL PROTECTED]
>>Sent: 26 February 2003 16:59
>>To: 'OJB Users List'
>>Subject: Ternary associations
>>
>>
>>Hi,
>>
>>According to the following, OJB is supposed to support ternary 
>>associations:
>>http://c2.com/cgi-bin/wiki?ObjectRelationalToolComparison
>>
>>I can't find any info on this.  Is it actually supported?
>>
>>Thanks,
>>John
>>***************************************************************
>>*********
>>This e-mail and any files transmitted with it are confidential 
>>and may be
>>privileged and are intended solely for the individual named/ 
>>for the use of
>>the individual or entity to whom they are addressed.If you are not the
>>intended addressee, you should not disseminate, distribute or 
>copy this
>>e-mail.Please notify the sender immediately if you have 
>>received this e-mail
>>by mistake and delete this e-mail from your system.If you are not the
>>intended recipient, you are notified that reviewing, 
>>disclosing, copying,
>>distributing or taking any action in reliance on the contents 
>>of this e-mail
>>is strictly prohibited.Please note that any views or opinions 
>>expressed in
>>this e-mail are solely those of the author and do not 
>>necessarily represent
>>those of Traventec Limited.E-mail transmission cannot be 
>>guaranteed to be
>>secure or error-free as information could be intercepted, 
>>corrupted, lost,
>>destroyed, or arrive late or incomplete.Traventec Limited 
>>therefore does not
>>accept liability for any errors or omissions in the contents of this
>>message, which arise as a result of e-mail transmission.The 
>>recipient should
>>check this e-mail and any attachments for the presence of viruses.This
>>e-mail has been swept for computer viruses however Traventec 
>>Limited accepts
>>no liability for any damage caused by any virus transmitted by 
>>this e-mail.
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>***************************************************************
>>*********
>>This e-mail and any files transmitted with it are confidential 
>>and may be
>>privileged and are intended solely for the individual named/ 
>>for the use of
>>the individual or entity to whom they are addressed.If you are not the
>>intended addressee, you should not disseminate, distribute or 
>copy this
>>e-mail.Please notify the sender immediately if you have 
>>received this e-mail
>>by mistake and delete this e-mail from your system.If you are not the
>>intended recipient, you are notified that reviewing, 
>>disclosing, copying,
>>distributing or taking any action in reliance on the contents 
>>of this e-mail
>>is strictly prohibited.Please note that any views or opinions 
>>expressed in
>>this e-mail are solely those of the author and do not 
>>necessarily represent
>>those of Traventec Limited.E-mail transmission cannot be 
>>guaranteed to be
>>secure or error-free as information could be intercepted, 
>>corrupted, lost,
>>destroyed, or arrive late or incomplete.Traventec Limited 
>>therefore does not
>>accept liability for any errors or omissions in the contents of this
>>message, which arise as a result of e-mail transmission.The 
>>recipient should
>>check this e-mail and any attachments for the presence of viruses.This
>>e-mail has been swept for computer viruses however Traventec 
>>Limited accepts
>>no liability for any damage caused by any virus transmitted by 
>>this e-mail.
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>
>
>
>This email and any attachments are strictly confidential and 
>are intended
>solely for the addressee. If you are not the intended 
>recipient you must
>not disclose, forward, copy or take any action in reliance on 
>this message
>or its attachments. If you have received this email in error 
>please notify
>the sender as soon as possible and delete it from your 
>computer systems.
>Any views or opinions presented are solely those of the author 
>and do not
>necessarily reflect those of HPD Software Limited or its affiliates.
>
> At present the integrity of email across the internet cannot 
>be guaranteed
>and messages sent via this medium are potentially at risk.  
>All liability
>is excluded to the extent permitted by law for any claims 
>arising as a re-
>sult of the use of this medium to transmit information by or to 
>HPD Software Limited or its affiliates.
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>***************************************************************
>*********
>This e-mail and any files transmitted with it are confidential 
>and may be
>privileged and are intended solely for the individual named/ 
>for the use of
>the individual or entity to whom they are addressed.If you are not the
>intended addressee, you should not disseminate, distribute or copy this
>e-mail.Please notify the sender immediately if you have 
>received this e-mail
>by mistake and delete this e-mail from your system.If you are not the
>intended recipient, you are notified that reviewing, 
>disclosing, copying,
>distributing or taking any action in reliance on the contents 
>of this e-mail
>is strictly prohibited.Please note that any views or opinions 
>expressed in
>this e-mail are solely those of the author and do not 
>necessarily represent
>those of Traventec Limited.E-mail transmission cannot be 
>guaranteed to be
>secure or error-free as information could be intercepted, 
>corrupted, lost,
>destroyed, or arrive late or incomplete.Traventec Limited 
>therefore does not
>accept liability for any errors or omissions in the contents of this
>message, which arise as a result of e-mail transmission.The 
>recipient should
>check this e-mail and any attachments for the presence of viruses.This
>e-mail has been swept for computer viruses however Traventec 
>Limited accepts
>no liability for any damage caused by any virus transmitted by 
>this e-mail.
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>


This email and any attachments are strictly confidential and are intended
solely for the addressee. If you are not the intended recipient you must
not disclose, forward, copy or take any action in reliance on this message
or its attachments. If you have received this email in error please notify
the sender as soon as possible and delete it from your computer systems.
Any views or opinions presented are solely those of the author and do not
necessarily reflect those of HPD Software Limited or its affiliates.

 At present the integrity of email across the internet cannot be guaranteed
and messages sent via this medium are potentially at risk.  All liability
is excluded to the extent permitted by law for any claims arising as a re-
sult of the use of this medium to transmit information by or to 
HPD Software Limited or its affiliates.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
************************************************************************
This e-mail and any files transmitted with it are confidential and may be
privileged and are intended solely for the individual named/ for the use of
the individual or entity to whom they are addressed.If you are not the
intended addressee, you should not disseminate, distribute or copy this
e-mail.Please notify the sender immediately if you have received this e-mail
by mistake and delete this e-mail from your system.If you are not the
intended recipient, you are notified that reviewing, disclosing, copying,
distributing or taking any action in reliance on the contents of this e-mail
is strictly prohibited.Please note that any views or opinions expressed in
this e-mail are solely those of the author and do not necessarily represent
those of Traventec Limited.E-mail transmission cannot be guaranteed to be
secure or error-free as information could be intercepted, corrupted, lost,
destroyed, or arrive late or incomplete.Traventec Limited therefore does not
accept liability for any errors or omissions in the contents of this
message, which arise as a result of e-mail transmission.The recipient should
check this e-mail and any attachments for the presence of viruses.This
e-mail has been swept for computer viruses however Traventec Limited accepts
no liability for any damage caused by any virus transmitted by this e-mail.

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

Reply via email to