db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Jefferson <a...@jpox.org>
Subject Re: Managed 1-1 relationiships
Date Thu, 21 Jul 2005 18:58:18 GMT
> 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>

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

-- 
Andy

Mime
View raw message