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 "Wright, Jim (NIH/CIT) [C]" <wr...@mail.nih.gov> on 2006/08/11 17:17:05 UTC

Key in object not propulated from Foreign key listed in reference-descriptor

I have a field in a class called IOS that is not getting populated from
the foreign key definition in the scientist reference-descriptor shown
in IOS class-descriptor.  Here is the class descriptor containing the
field scid that is not getting populated on insertion:

 

<class-descriptor

   class="gov.nih.nidb.persistent.IOS"

   table="NSD.IPID_ORID_SCID"

   >

  <field-descriptor

     name="ipid"

     column="ipid"

     jdbc-type="BIGINT"

     primarykey="true"

     />

  <field-descriptor

     name="scid"

     column="scid"

     jdbc-type="VARCHAR"

     primarykey="true"

     />

  <field-descriptor

     name="orid"

     column="orid"

     jdbc-type="VARCHAR"

     primarykey="true"

     />

  <field-descriptor

     name="order"

     column="orders"

     jdbc-type="Integer"

     />

  <field-descriptor

     name="role"

     column="role"

     jdbc-type="VARCHAR"

     />

  <field-descriptor

     name="modificationDate"

     column="mdate"

     jdbc-type="TIMESTAMP"

     access="readonly"

     />

  <field-descriptor

     name="year"

     column="ryear"

     jdbc-type="INTEGER"

     />

  <field-descriptor

     name="fte"

     column="fte"

     jdbc-type="DOUBLE"

     />

  <reference-descriptor name="report"

                  class-ref="gov.nih.nidb.persistent.Report">

    <foreignkey field-ref="ipid" />

  </reference-descriptor>

  <reference-descriptor name="scientist"

                  class-ref="gov.nih.nidb.persistent.Scientist">

    <foreignkey field-ref="scid" />

  </reference-descriptor>

</class-descriptor>

 

The ipid field is getting populated from the report class correctly.
Does anyone know what the cause of the problem might be?

Jim Wright 

 


RE: Key in object not propulated from Foreign key listed in reference-descriptor

Posted by "Wright, Jim (NIH/CIT) [C]" <wr...@mail.nih.gov>.
Hello, I configured spy6py per the FAQ section in the OJB documentation
on the Apache web site.  I was unable to get it to work and it
complained with the message-"Unable to find suitable driver."  It sounds
like a very helpful tool if I could get it to work.  I tried it one
other time and could not get it to work.

Jim Wright 

-----Original Message-----
From: Thomas Dudziak [mailto:tomdzk@gmail.com] 
Sent: Monday, August 14, 2006 11:43 PM
To: OJB Users List
Subject: Re: Key in object not propulated from Foreign key listed in
reference-descriptor

On 8/11/06, Wright, Jim (NIH/CIT) [C] <wr...@mail.nih.gov> wrote:

> Tom, I also did a little experiment to see the order in which each
> object is inserted by the store method.  However the only one that
> appeared to be inserted was my report object which is the parent of
> scientist and IOS objects.  I was hoping I could at least try putting
> the current scid value into the scid field of IOS.  However IOS
inserted
> but I had no relative idea when it was inserted due to the inability
to
> get the "firing sequence" of the inserts.  I don't like to work around
> the whole idea of ORM but since I cannot change our database I was
> hoping for a workaround.

Mhmm, references and collections are only inserted if the auto-update
property in the corresponding descriptor is set to 'object' (or 'true'
which is the older name).
If you want to see what is happening, configure P6Spy (there's a FAQ
entry for that) and check the SQL that OJB generates.

But in general, it is not such a good idea to use PK fields for FK
fields. As I said, the identity of the object will change if you
change its reference to point to another object. And ORM tools like
OJB depend on the identity. This is what defines the object: different
PKs = different objects.

Tom

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

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


Re: Key in object not propulated from Foreign key listed in reference-descriptor

Posted by Thomas Dudziak <to...@gmail.com>.
On 8/11/06, Wright, Jim (NIH/CIT) [C] <wr...@mail.nih.gov> wrote:

> Tom, I also did a little experiment to see the order in which each
> object is inserted by the store method.  However the only one that
> appeared to be inserted was my report object which is the parent of
> scientist and IOS objects.  I was hoping I could at least try putting
> the current scid value into the scid field of IOS.  However IOS inserted
> but I had no relative idea when it was inserted due to the inability to
> get the "firing sequence" of the inserts.  I don't like to work around
> the whole idea of ORM but since I cannot change our database I was
> hoping for a workaround.

Mhmm, references and collections are only inserted if the auto-update
property in the corresponding descriptor is set to 'object' (or 'true'
which is the older name).
If you want to see what is happening, configure P6Spy (there's a FAQ
entry for that) and check the SQL that OJB generates.

But in general, it is not such a good idea to use PK fields for FK
fields. As I said, the identity of the object will change if you
change its reference to point to another object. And ORM tools like
OJB depend on the identity. This is what defines the object: different
PKs = different objects.

Tom

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


RE: Key in object not propulated from Foreign key listed in reference-descriptor

Posted by "Wright, Jim (NIH/CIT) [C]" <wr...@mail.nih.gov>.
Tom, I also did a little experiment to see the order in which each
object is inserted by the store method.  However the only one that
appeared to be inserted was my report object which is the parent of
scientist and IOS objects.  I was hoping I could at least try putting
the current scid value into the scid field of IOS.  However IOS inserted
but I had no relative idea when it was inserted due to the inability to
get the "firing sequence" of the inserts.  I don't like to work around
the whole idea of ORM but since I cannot change our database I was
hoping for a workaround.

Jim Wright [Contractor - SRA International]

Web Developer

Web Development Team

Custom Applications Branch (CAB)

Division of Enterprise and Custom Applications, CIT/NIH/DHHS

6707 Democracy Blvd, Suite 304

Bethesda, MD 20892

Office: 301.

Email: wrightjr@mail.nih.gov

URL: http://webdev.cit.nih.gov/

-----Original Message-----
From: Thomas Dudziak [mailto:tomdzk@gmail.com] 
Sent: Friday, August 11, 2006 12:16 PM
To: OJB Users List
Subject: Re: Key in object not propulated from Foreign key listed in
reference-descriptor

On 8/11/06, Wright, Jim (NIH/CIT) [C] <wr...@mail.nih.gov> wrote:

> I have a field in a class called IOS that is not getting populated
from
> the foreign key definition in the scientist reference-descriptor shown
> in IOS class-descriptor.

My guess is that your problem stems from the fact that you use primary
key fields for your foreign key fields which often leads to problems.
In general you should not do that - if you change the reference to
another object, then the identity of your object will change as well
which is most certainly not what you want.
Rather use seperate non-PK fields for the references. Or if the Report
and Scientist classes link back to the IOS class (bi-directional
link), then use collections instead in the IOS class.

Tom

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

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


Re: Key in object not propulated from Foreign key listed in reference-descriptor

Posted by Thomas Dudziak <to...@gmail.com>.
On 8/11/06, Wright, Jim (NIH/CIT) [C] <wr...@mail.nih.gov> wrote:

> I have a field in a class called IOS that is not getting populated from
> the foreign key definition in the scientist reference-descriptor shown
> in IOS class-descriptor.

My guess is that your problem stems from the fact that you use primary
key fields for your foreign key fields which often leads to problems.
In general you should not do that - if you change the reference to
another object, then the identity of your object will change as well
which is most certainly not what you want.
Rather use seperate non-PK fields for the references. Or if the Report
and Scientist classes link back to the IOS class (bi-directional
link), then use collections instead in the IOS class.

Tom

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