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 airwing <ai...@vip.sina.com> on 2003/09/18 07:11:32 UTC

update for 1:1 relation

Hi,

I'd like to know if it would be possible to update a reference just by
updating the FK field without updating the referenced object.

Example: the class Software references the class Editor with a 1:1
relation. So the class Software contains a (Editor) editor field and an
(int) editorId (which is the FK).

If I have to change the editor of a particular software, I have to:

1) Retrieve the correct Software object.
1) Instanciate a new Editor object (or retrieving a existing one from a
broker request).
3) Call the setEditor() method of the Software object.
4) Store the Software object.

Note that if I just call the setEditorId() of the Software object, the
reference is not well updated (until the next application restart),
although the editorId field is well updated in the DB. So I have to do
the entire process mentioned previously if I want my referenced objects
to be well updated.

That's a good way, but in some cases it could be considered as a heavy
process because I have *already* the correct Editor PK (in fact this is
a usual case in my app). In these cases, directly updating the FK of the
Software object (without instancing or loading an entire Editor object)
would be really appreciated isn't it? Maybe this method shouldn't be
considered as very elegant one from a persistence layer point of view
(which tends to manage the PK and FK in a transparent way), but what
about the performances?





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


Re: update for 1:1 relation

Posted by LAURENT Stephane <sl...@adequates.com>.
You can try this way :
  <class-descriptor class="CompleteA" table="A">
 <field-descriptor id="1" name="id" column="AID" jdbc-type="BIGINT" primarykey="true" autoincrement="true"/>
...
<field-descriptor id="99" name="id" column="BID" jdbc-type="BIGINT"/>
 <reference-descriptor name="fieldB" class-ref="B">
  <foreignkey field-ref="Bid"/>
 </reference-descriptor>
   </class-descriptor>

 <class-descriptor class="B" table="B">
 <field-descriptor id="1" name="Bid" column="BID" jdbc-type="BIGINT" primarykey="true" autoincrement="true"/>
...
   </class-descriptor>

  <class-descriptor class="PartialA" table="A">
 <field-descriptor id="1" name="id" column="AID" jdbc-type="BIGINT" primarykey="true" autoincrement="true"/>
...
<field-descriptor id="99" name="id" column="BID" jdbc-type="BIGINT"/>
   </class-descriptor>

simply create PartialA.class and CompleteA.class classes extends A.class

When you want to update A with only PK, get PartialA object
When you want to update A with B reference, get CompleteA object

test by storing an updated PartialA object and get the same record as CompleteA.
Probably you have to declare extend on repository but not necessary (seems to work for me with PB API but we only have 1:n reference and use auto-refresh=true ...)

hope it can help you.
Regards.
  ----- Original Message ----- 
  From: airwing 
  To: ojb-user@db.apache.org 
  Sent: Thursday, September 18, 2003 7:11 AM
  Subject: update for 1:1 relation


  Hi,

  I'd like to know if it would be possible to update a reference just by
  updating the FK field without updating the referenced object.

  Example: the class Software references the class Editor with a 1:1
  relation. So the class Software contains a (Editor) editor field and an
  (int) editorId (which is the FK).

  If I have to change the editor of a particular software, I have to:

  1) Retrieve the correct Software object.
  1) Instanciate a new Editor object (or retrieving a existing one from a
  broker request).
  3) Call the setEditor() method of the Software object.
  4) Store the Software object.

  Note that if I just call the setEditorId() of the Software object, the
  reference is not well updated (until the next application restart),
  although the editorId field is well updated in the DB. So I have to do
  the entire process mentioned previously if I want my referenced objects
  to be well updated.

  That's a good way, but in some cases it could be considered as a heavy
  process because I have *already* the correct Editor PK (in fact this is
  a usual case in my app). In these cases, directly updating the FK of the
  Software object (without instancing or loading an entire Editor object)
  would be really appreciated isn't it? Maybe this method shouldn't be
  considered as very elegant one from a persistence layer point of view
  (which tends to manage the PK and FK in a transparent way), but what
  about the performances?





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



  ---
  Outgoing mail is certified Virus Free.
  Checked by AVG anti-virus system (http://www.grisoft.com).
  Version: 6.0.519 / Virus Database: 317 - Release Date: 17/09/2003