David Zejda wrote:

What's wrong with the classes below?
The "We" instance loaded from db has "master_id" property set correctly, but the "we" property is null.


public class Subject
{
    /**
     * Artificial ID key holder
     *
     * @ojb.field nullable="false"
     *            autoincrement="ojb"
     *            primarykey="true"
     */
    private int a_id;

    /**
     * Creates _invalid_ instance
     * Behavior will be unpredictable until properties are filled.
     */
    public Subject()
    {
    }
}

public class We
{
    /** Creates a new instance of We */
    public We()
    {
    }

    /**
     * @ojb.reference class-ref="test.Subject"
     *                foreignkey="master_id"
     *                auto-retrieve="true"
     *                auto-update="true"
     *                auto-delete="true"
     */
    public Subject we;

    /**
     * Referential ID key holder
     * Primary key, becouse only marks
     *
     * @ojb.field nullable="false"
     *            primarykey="true"
     */
    private int master_id;
}

You shouldn't use the primarykey of We as the foreignkey for the instance of Subject. The foreignkey will be filled with the primarykey value of the Subject instance when you store the We object and it has an associated Subject object.
Instead add an additional field to the We class, e.g. int subject_id, and use it for the foreignkey of the we attribute.


Btw, you should also use Integer instead of int for the primarykey (and foreignkey) field (has to do with the representation of an empty reference in the database).

Tom

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to