You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by David Zejda <dv...@atlas.cz> on 2004/07/23 18:32:34 UTC

property value is not auto-retrieved

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;
}

Thanks!
David

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: property value is not auto-retrieved

Posted by David Zejda <dv...@atlas.cz>.
Sorry - it seems that the bug is elsewhere - in a controller being used 
to manage persistence, so don't fiddle it more..
One way or another, thanks for your suggestion to use Integers instead 
of ints as a type for keys..

David

> Thanks for a quick reply.
> I corrected the classes as you suggested, but the problem remains :(
> Is there ill something else?


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: property value is not auto-retrieved

Posted by David Zejda <dv...@atlas.cz>.
> 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

Thanks for a quick reply.
I corrected the classes as you suggested, but the problem remains :(
Is there ill something else?

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

     public Subject()
     {
     }
}

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


     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"
      */
     private Integer master_id;
}

David

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: property value is not auto-retrieved

Posted by Thomas Dudziak <to...@first.fhg.de>.
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: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org