Armin, It is the same problem I am running into, I hoped anonymous keys can
solve this but they didn't.

Jure, thank you for the solution to call broker.retrieveAllReferences(mg21);
Here is what I did as a fast workaround of this bug:

Class Parent {
 private String foreignKey;
 private Child child;

        public void setForeignKey(String key){
                this. foreignKey = key;
                child. setForeignKey(key);
        }
}

In this case you avoid the cost of calling
broker.retrieveAllReferences(mg21);
When all you want is to store the object in DB.


-Sergey







-----Original Message-----
From: Armin Waibel [mailto:[EMAIL PROTECTED] 
Sent: Monday, January 26, 2004 5:04 AM
To: OJB Users List
Subject: Re: Do I need to create reference objects when storing object?

Hi Jure,

in a first scan I found

- an 'access' attribute in reference-descriptor of Bmg21. I think 
reference-descriptor doesn't support such an attribute.

- in reference-descriptor you set auto-update 'false'. Thus OJB will not 
store references automatic and set mg21_id, mg21_str to null. Think the 
problem is that OJB override the FK fields values with null, because the 
reference object Bmt05 was not found.
I'm not sure, but this sounds like a bug. If the FK fields are set (non 
null), then OJB shouldn't override these values on insert.


 > But if I add
 >
 >
 >
 > broker.retrieveAllReferences(mg21);
 >
 >
 >
 > before calling broker.store(mg21)
 >
 >
 >
 > then the object mg21 is stored without any errors.

I assume Bmt05 object already exists.
broker.retrieveAllReferences(mg21);
materialize the Bmt05 reference in mg21. Now OJB find FK values for 
mg21_id, mg21_str in the materialized Bmt05 object.



regards,
Armin


Jurica Viskovic wrote:
> Thanks Armin for taking the time 
> 
> 
> 
> Ok, this is my reporitory_user.xml
> 
> 
> 
> <class-descriptor class="model.obrazci.Bmg21" table="MG21">
> 
>     <field-descriptor id="1" name="mg21_xx" column="MG21_XX" jdbc-
> 
> type="INTEGER" primarykey="true"/>
> 
>     <field-descriptor id="2" name="mg21_id" column="MG21_ID" jdbc-
> 
> type="VARCHAR"/>
> 
>     <field-descriptor id="3" name="mg21_str" column="MG21_STR" jdbc-
> 
> type="VARCHAR"/>
> 
>     <field-descriptor id="4" name="mg21_stat" column="MG21_STAT" jdbc-
> 
> type="INTEGER"/>
> 
>     <field-descriptor id="5" name="mg21_user" column="MG21_USER" jdbc-
> 
> type="VARCHAR"/>
> 
>     <field-descriptor id="6" name="mg21_used" column="MG21_USED" jdbc-
> 
> type="TIMESTAMP"/>
> 
>     <field-descriptor id="7" name="mg21_rowf" column="MG21_ROWF" jdbc-
> 
> type="INTEGER"/>
> 
>     <field-descriptor id="8" name="mg21_comf" column="MG21_COMF" jdbc-
> 
> type="INTEGER"/>
> 
>     <field-descriptor id="9" name="mg21_shif" column="MG21_SHIF" jdbc-
> 
> type="VARCHAR"/>
> 
>     <reference-descriptor name="mt05" class-ref="model.items.Bmt05"
> 
>         refresh="true" auto-retrieve="true"  auto-update="false" 
> 
> access="readonly">
> 
>         <foreignkey field-ref="mg21_id" />
> 
>         <foreignkey field-ref="mg21_str" />
> 
> </reference-descriptor>
> 
> 
> 
> <class-descriptor class="model.items.Bmt05" table="MT05">
> 
>     <field-descriptor id="1" name="mt05_id" column="MT05_ID" jdbc-
> 
> type="VARCHAR" primarykey="true" />
> 
>     <field-descriptor id="2" name="mt05_str" column="MT05_STR" jdbc-
> 
> type="VARCHAR" primarykey="true"  />
> 
>     <field-descriptor id="3" name="mt05_koo" column="MT05_KOO" jdbc-
> 
> type="VARCHAR"/>
> 
>     <field-descriptor id="4" name="mt05_mid" column="MT05_MID" jdbc-
> 
> type="VARCHAR"/>
> 
>     <field-descriptor id="5" name="mt05_name" column="MT05_NAME" jdbc-
> 
> type="VARCHAR"/>
> 
>     <field-descriptor id="6" name="mt05_rowf" column="MT05_ROWF" jdbc-
> 
> type="INTEGER"/>
> 
>     <field-descriptor id="7" name="mt05_sfi" column="MT05_SFI" jdbc-
> 
> type="VARCHAR"/>
> 
> </class-descriptor>
> 
> 
> 
>
----------------------------------------------------------------------------
---
> 
> --------------------------------------------------------------------------
> 
> 
> 
> When I create
> 
> 
> 
> Bmg21 mg21 = new Bmg21();
> 
> mg21.setMg21_xx(100);
> 
> mg21.setMg21_id("BLABLA");
> 
> mg21.setMg21_str("ZLS");
> 
> 
> 
> 
> 
> and than try to save this object OJB sets mg21_id and mg21_str to null and
I 
> 
> get exception that I can't insert null into MG21_ID.
> 
> This is the source code
> 
>       try{
> 
>                         broker.beginTransaction();
> 
>                         broker.store(mg21);
> 
>                         broker.commitTransaction();
> 
>                      }catch(PersistenceBrokerException e){
> 
>                         broker.abortTransaction();
> 
>                         broker.close();
> 
>                         logger.error("ERROR "+e.getMessage());
> 
>                         return false;
> 
>                      }
> 
> 
> 
> But if I add 
> 
> 
> 
> broker.retrieveAllReferences(mg21);
> 
> 
> 
> before calling broker.store(mg21)
> 
> 
> 
> then the object mg21 is stored without any errors.
> 
> 
> 
> This is the source code
> 
>       try{
> 
>                         broker.beginTransaction();
> 
>                         broker.retrieveAllReferences(mg21);
> 
>                         broker.store(mg21);
> 
>                         broker.commitTransaction();
> 
>                      }catch(PersistenceBrokerException e){
> 
>                         broker.abortTransaction();
> 
>                         broker.close();
> 
>                         logger.error("ERROR "+e.getMessage());
> 
>                         return false;
> 
>                      }
> 
> 
> 
> The same thing happens if i manually create Bmt05 for example
> 
>       
> 
>               try{
> 
>                     broker.beginTransaction();
> 
>                     
> 
>           mg21.setMt05(new Bmt05());
> 
>                     mg21.getMt05().setMt05_id(mg21.getMg21_id());
> 
>                     mg21.getMt05().setMt05_str(mg21.getMg21_str());
> 
>                     
> 
>                     broker.store(mg05);
> 
>                     broker.commitTransaction();
> 
>                  }catch(PersistenceBrokerException ex){
> 
>                     broker.abortTransaction();
> 
>                     broker.close();
> 
>                     System.out.println(ex.getMessage());
> 
>                     ex.printStackTrace();
> 
>                     return false;
> 
>                  }
> 
> 
> 
> then the object mg21 is stored without any errors.
> 
> 
> 
> I can call broker.retrieveAllReferences(mg21);
> 
> every time I save some object but what about performance.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 



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

**********************
** LEGAL DISCLAIMER **
**********************

This E-mail message and any attachments may contain 
legally privileged, confidential or proprietary 
information. If you are not the intended recipient(s),
or the employee or agent responsible for delivery of 
this message to the intended recipient(s), you are 
hereby notified that any dissemination, distribution 
or copying of this E-mail message is strictly 
prohibited. If you have received this message in 
error, please immediately notify the sender and 
delete this E-mail message from your computer.

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

Reply via email to