You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Nat Gross <na...@gmail.com> on 2007/08/21 22:51:10 UTC

ManyToMany - with a twist

[In an existing ejb 2 application] I have an interesting manytomany
scenario.

Class EntityA with a 1 field Integer pk can relate to other instances of
itself in more than one way.
Not only can it have many  EntityA children and have many EntityA parents it
can have the SAME EntityA Parent/Child more than once.
Each EntityA needs a reason as to why it relates to the other EntityA.
(Suppose EntityA is a Person that can relate to another Person in more than
one way, say a cousin,  a spouse, employer, business partner. [ahem<g>])
Currently I have a table, ARELATIONS, with three Integer fields: srcPK,
targetPK, relateType. All three fields make up the PK. Currently I am
manually controlling the joins of this table with EntityA. I would like to
utilize jpa to do this.

Also important to note is that it is not enough for the end-user to simply
fetch related EntityA records, the *reason* (relateType) is also important.

Basically I should be able to define two OneToMany Unidirectional
Collection<Arelations> fields in EntityA, but whatever I try with Toplink I
get different problems. (Basically, Toplink wants yet another intersection
table, which I don't want.)
I hope openjpa has a better solution.
Please adivse.

Thanks
natG

Re: ManyToMany - with a twist

Posted by Nat Gross <na...@gmail.com>.
Well, not exactly.
However I happened to pageDn from that link you provided and in 7.7 I found
the answer!
http://openjpa.apache.org/docs/nightly/manual/manual.html#ref_guide_mapping_jpa_onemany

This is an openjpa enhancement over the standard spec.

Thanks,
natG

On 8/22/07, Patrick Linskey <pl...@gmail.com> wrote:
>
> Hi,
>
> It sounds like you're looking for OpenJPA's constant join behavior.
> You can read about it at
>
> http://openjpa.apache.org/docs/nightly/manual/manual.html#ref_guide_mapping_notes_nonstdjoins
>
> -Patrick
>
> On 8/21/07, Nat Gross <na...@gmail.com> wrote:
> > [In an existing ejb 2 application] I have an interesting manytomany
> > scenario.
> >
> > Class EntityA with a 1 field Integer pk can relate to other instances of
> > itself in more than one way.
> > Not only can it have many  EntityA children and have many EntityA
> parents it
> > can have the SAME EntityA Parent/Child more than once.
> > Each EntityA needs a reason as to why it relates to the other EntityA.
> > (Suppose EntityA is a Person that can relate to another Person in more
> than
> > one way, say a cousin,  a spouse, employer, business partner. [ahem<g>])
> > Currently I have a table, ARELATIONS, with three Integer fields: srcPK,
> > targetPK, relateType. All three fields make up the PK. Currently I am
> > manually controlling the joins of this table with EntityA. I would like
> to
> > utilize jpa to do this.
> >
> > Also important to note is that it is not enough for the end-user to
> simply
> > fetch related EntityA records, the *reason* (relateType) is also
> important.
> >
> > Basically I should be able to define two OneToMany Unidirectional
> > Collection<Arelations> fields in EntityA, but whatever I try with
> Toplink I
> > get different problems. (Basically, Toplink wants yet another
> intersection
> > table, which I don't want.)
> > I hope openjpa has a better solution.
> > Please adivse.
> >
> > Thanks
> > natG
> >
>
>
> --
> Patrick Linskey
> 202 669 5907
>

Re: ManyToMany - with a twist

Posted by Patrick Linskey <pl...@gmail.com>.
Hi,

It sounds like you're looking for OpenJPA's constant join behavior.
You can read about it at
http://openjpa.apache.org/docs/nightly/manual/manual.html#ref_guide_mapping_notes_nonstdjoins

-Patrick

On 8/21/07, Nat Gross <na...@gmail.com> wrote:
> [In an existing ejb 2 application] I have an interesting manytomany
> scenario.
>
> Class EntityA with a 1 field Integer pk can relate to other instances of
> itself in more than one way.
> Not only can it have many  EntityA children and have many EntityA parents it
> can have the SAME EntityA Parent/Child more than once.
> Each EntityA needs a reason as to why it relates to the other EntityA.
> (Suppose EntityA is a Person that can relate to another Person in more than
> one way, say a cousin,  a spouse, employer, business partner. [ahem<g>])
> Currently I have a table, ARELATIONS, with three Integer fields: srcPK,
> targetPK, relateType. All three fields make up the PK. Currently I am
> manually controlling the joins of this table with EntityA. I would like to
> utilize jpa to do this.
>
> Also important to note is that it is not enough for the end-user to simply
> fetch related EntityA records, the *reason* (relateType) is also important.
>
> Basically I should be able to define two OneToMany Unidirectional
> Collection<Arelations> fields in EntityA, but whatever I try with Toplink I
> get different problems. (Basically, Toplink wants yet another intersection
> table, which I don't want.)
> I hope openjpa has a better solution.
> Please adivse.
>
> Thanks
> natG
>


-- 
Patrick Linskey
202 669 5907