You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Donald Woods <dw...@apache.org> on 2009/02/11 15:19:23 UTC
Question about JUnit Bi-directional and OneToOne tests
I would expect the BidiParent/BidiChild entities under -
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/
to have a bi-directional mappedBy annotation for the OneToOne relations,
but the child doesn't -
BidiParent -
@OneToOne(fetch=FetchType.LAZY, mappedBy="oneToOneParent")
private BidiChild oneToOneChild;
BidiChild -
@OneToOne(fetch=FetchType.LAZY)
private BidiParent oneToOneParent;
Is this correct?
-Donald
Re: Question about JUnit Bi-directional and OneToOne tests
Posted by Donald Woods <dw...@apache.org>.
Thanks. I was trying to map the NullRelations testcase from David
Blevins to an existing junit testcase, but realized after I sent the
email that David's testcase is using 3 entities and 2 of them are using
join-columns.
-Donald
Kevin Sutter wrote:
> Don,
> Good question. A bidirectional one-to-one relationship requires a mappedBy
> element, but only on one side of the relationship. Not both. In this
> particular case, the mappedBy element indicates that the BidiChild is the
> owning entity for this relationship (based on the oneToOneParent
> attribute). A general rule is that the mappedBy element is never on both
> sides of a relationship.
>
> Kevin
>
> On Wed, Feb 11, 2009 at 8:19 AM, Donald Woods <dw...@apache.org> wrote:
>
>> I would expect the BidiParent/BidiChild entities under -
>>
>> openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/
>> to have a bi-directional mappedBy annotation for the OneToOne relations,
>> but the child doesn't -
>>
>> BidiParent -
>> @OneToOne(fetch=FetchType.LAZY, mappedBy="oneToOneParent")
>> private BidiChild oneToOneChild;
>>
>> BidiChild -
>> @OneToOne(fetch=FetchType.LAZY)
>> private BidiParent oneToOneParent;
>>
>>
>> Is this correct?
>>
>>
>> -Donald
>>
>
Re: Question about JUnit Bi-directional and OneToOne tests
Posted by Kevin Sutter <kw...@gmail.com>.
Don,
Good question. A bidirectional one-to-one relationship requires a mappedBy
element, but only on one side of the relationship. Not both. In this
particular case, the mappedBy element indicates that the BidiChild is the
owning entity for this relationship (based on the oneToOneParent
attribute). A general rule is that the mappedBy element is never on both
sides of a relationship.
Kevin
On Wed, Feb 11, 2009 at 8:19 AM, Donald Woods <dw...@apache.org> wrote:
> I would expect the BidiParent/BidiChild entities under -
>
> openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/
> to have a bi-directional mappedBy annotation for the OneToOne relations,
> but the child doesn't -
>
> BidiParent -
> @OneToOne(fetch=FetchType.LAZY, mappedBy="oneToOneParent")
> private BidiChild oneToOneChild;
>
> BidiChild -
> @OneToOne(fetch=FetchType.LAZY)
> private BidiParent oneToOneParent;
>
>
> Is this correct?
>
>
> -Donald
>