db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Watzek <mwa.t...@spree.de>
Subject Re: Managed 1-1 relationiships
Date Fri, 22 Jul 2005 09:34:23 GMT
Hi Andy,

comments inline:

>>testing 1-1 relationships I encountered that the JPOX enhancer generates
>>code for managed relationships if the orm meta data contains attribute
>>"mapped-by" on a field element. Thus setting one side of the
>>relationship implies setting the other side, too. The decompiled
>>enhanced code looks like this:
>>
>>     public void setMentor(Employee mentor)
>>     {
>>         jdoSetmentor(this, mentor);
>>         jdoSetprotege(mentor, this);
>>     }
>>     public void setProtege(Employee protege)
>>     {
>>         jdoSetprotege(this, protege);
>>         jdoSetmentor(protege, this);
>>     }
> 
> 
> Hi Michael,
> not sure how you got it to give that but it sure doesn't for me ;-)
> I'll give you a test case to demonstrate the point (and you can point out 
> where your case is different) ...
> 
> public class Child
> {
>     private Parent parent;
>     public setParent(Parent parent)
>     {
>         this.parent = parent;
>     }
> }
> public class Parent
> {
>     private Child child = null;
>     public void setChild(Child child)
>     {
>         this.child = child;
>     }
> }
> 
> <jdo>
>     <package name="org.jpox.samples">
>         <class name="Child" detachable="true">
>             <field name="parent" persistence-modifier="persistent"/>
>         </class>
> 
>         <class name="Parent" detachable="true">
>             <field name="child" persistence-modifier="persistent" 
> mapped-by="parent"/>
>         </class>
>     </package>
> </jdo>
In my case, the identity type is datastore and there are separate files
for jdo metadata and orm metadata. The orm metadata file contains the
"mapped-by" attribute. I attached .java, .jdo, and .orm. I did not 
attach the schema file because the attachement would become too big for 
Apache. If you like to see it, let me know. Class "Employee" has fields 
"mentor" and "protege". Field "protege" is
mapped by field "mentor".

I use JPOX enhancer+runtime nightly build of 14th Jul. Hope that helps.

Regards,
Michael
> 
> And I get the following enhanced classes mutator methods
> public class Child implements PersistenceCapable, ...
> {
>     ...
>     public void setParent(Parent parent) {
>         jdoSetparent(this, parent);
>     }
> }
> public class Parent implements PersistenceCapable, ...
> {
>     ...
>     public void setChild(Child child) {
>         jdoSetchild(this, child);
>     }
> }
> 
> Looks right to me
> 


-- 
-------------------------------------------------------------------
Michael Watzek                  Tech@Spree Engineering GmbH
mailto:mwa.tech@spree.de        Buelowstr. 66
Tel.:  ++49/30/235 520 36       10783 Berlin - Germany
Fax.:  ++49/30/217 520 12       http://www.spree.de/
-------------------------------------------------------------------

Mime
View raw message