You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Alexander Saint Croix <sa...@gmail.com> on 2007/12/13 23:54:50 UTC
OneToMany(mappedBy...) special case
Hello again,
I have been having a little difficulty determining how to map a special case
of a OneToMany relationship between two of my entity beans.
The first bean, PartyRole, defines a OneToMany relationship to the second
bean, PartyRelationship by way of a Set<PartyRelationship>. The second
bean, PartyRelationship, has TWO mappings back to PartyRole.
PrimaryPartyRole and SecondaryPartyRole. PrimaryPartyRole and
SecondaryPartyRole. Each of these mappings should be ManyToOne. The
relationship is bidirectional in each case.
However, I'm not sure whether there is a way to define the "mappedBy"
annotation attribute in PartyRole to correctly identify each field as owning
side of their respective relationship. Can I say
@OneToMany(mappedBy="primaryPartyRole, secondaryPartyRole")? Something
tells me no.
If this is not possible, is there another way to accomplish this? Perhaps
an object that represents a link table between these two entities?
Kind regards,
--
Alexander R. Saint Croix
Re: OneToMany(mappedBy...) special case
Posted by Alexander Saint Croix <sa...@gmail.com>.
Gene,
This is actually a great idea. I think I'll take the suggestion.
Warm regards,
--
Alex
On Dec 14, 2007 1:03 AM, Gene Woo <ge...@gmail.com> wrote:
> Hi,
>
> PartyRole could have 2 fields in Set<PartyRelationship>:
> * private @OneToMany(mappedBy="primaryPartyRole")Set<PartyRelationship>
> primaryRelationships;
> private @OneToMany(mappedBy="secondaryPartyRole")Set<PartyRelationship>
> secondaryRelationships;*
>
> then you could have a method to merge then together. Set is quite easy to
> merge, right?
> *public Set<PartyRelationship> getPartyRelationships();*
>
> In my opinion, the combination of primaryRelationships and
> sencondaryRelationships is a business view of PartyRole model. So you
> probably have separate field for persistence purpose.
>
> Thanks,
>
> Gene.
Re: OneToMany(mappedBy...) special case
Posted by Gene Woo <ge...@gmail.com>.
Hi,
PartyRole could have 2 fields in Set<PartyRelationship>:
* private @OneToMany(mappedBy="primaryPartyRole")Set<PartyRelationship>
primaryRelationships;
private @OneToMany(mappedBy="secondaryPartyRole")Set<PartyRelationship>
secondaryRelationships;*
then you could have a method to merge then together. Set is quite easy to
merge, right?
*public Set<PartyRelationship> getPartyRelationships();*
In my opinion, the combination of primaryRelationships and
sencondaryRelationships is a business view of PartyRole model. So you
probably have separate field for persistence purpose.
Thanks,
Gene.
On Dec 14, 2007 6:54 AM, Alexander Saint Croix <sa...@gmail.com>
wrote:
> Hello again,
>
> I have been having a little difficulty determining how to map a special
> case
> of a OneToMany relationship between two of my entity beans.
>
> The first bean, PartyRole, defines a OneToMany relationship to the second
> bean, PartyRelationship by way of a Set<PartyRelationship>. The second
> bean, PartyRelationship, has TWO mappings back to PartyRole.
> PrimaryPartyRole and SecondaryPartyRole. PrimaryPartyRole and
> SecondaryPartyRole. Each of these mappings should be ManyToOne. The
> relationship is bidirectional in each case.
>
> However, I'm not sure whether there is a way to define the "mappedBy"
> annotation attribute in PartyRole to correctly identify each field as
> owning
> side of their respective relationship. Can I say
> @OneToMany(mappedBy="primaryPartyRole, secondaryPartyRole")? Something
> tells me no.
>
> If this is not possible, is there another way to accomplish this? Perhaps
> an object that represents a link table between these two entities?
>
> Kind regards,
> --
> Alexander R. Saint Croix
>
--
Best Regards,
Gene Woo