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 Jurica Viskovic <ju...@net.hr> on 2004/01/22 09:44:46 UTC
Do I need to create reference objects when storing object?
Please help!
In the previous versions of OJB it wasn’t necessary to create reference object
when storing object that has reference but when I try the same thing with OJB
1.0 RC5 the FK fields are set by OJB to null.
Is creating the reference object
the right thing to do or is there some way to disable this ojb functionality?
Thank,
Jure
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Do I need to create reference objects when storing object?
Posted by Jurica Viskovic <ju...@net.hr>.
THANKS!
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Do I need to create reference objects when storing object?
Posted by Armin Waibel <ar...@code-au-lait.de>.
Hi,
> In the previous versions of OJB it wasn’t necessary to create
reference object
>
> when storing object that has reference but when I try the same thing
with OJB
>
> 1.0 RC5 the FK fields are set by OJB to null.
>
> Is creating the reference object
>
> the right thing to do or is there some way to disable this ojb
> functionality?
>>
>> Why this is not the case with OJB 0.9.7!
>> Because I used OJB 0.9.7 for half of year and there were no problems!
ok, I changed this behaviour in CVS head. Now it is possible to store a
*new* pc object with populated FK, but without materialized reference.
The FK fields are not set to null.
Note: This only works for insert operations (storing of new objects),
for update the FK fields will be set to null, when reference object is null.
regards,
Armin
Armin Waibel wrote:
> Hi again,
>
> I will write some tests for the problem and try to fix it (if possible
> ;-)) before new release.
>
> regards,
> Armin
>
> Jurica Viskovic wrote:
>
>> Hy Armin
>>
>>
>>
>> Thank you for replaying so quickly.
>>
>>
>>
>> About the 'access' attribute in reference-descriptor of Bmg21. That's my
>> stupidity because I read in some blog that it could help and I
>> forgotten to
>> move it later on.
>>
>>
>>
>>
>> Object Bmt05 object exists. So there is no problem there.
>>
>>
>>
>> Going through the source code of the PersistenceBrokerImpl
>>
>> I found out that assertFkAssignment and storeReferences methods
>>
>> are setting my fields to null but I don't know why??
>>
>>
>>
>> Why this is not the case with OJB 0.9.7!
>> Because I used OJB 0.9.7 for half of year and there were no problems!
>>
>>
>>
>>
>> If this is the bug is there some way to fix it before the new release!
>>
>>
>>
>>
>>
>> Thanks,
>>
>> Jure
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Do I need to create reference objects when storing object?
Posted by Armin Waibel <ar...@code-au-lait.de>.
Hi again,
I will write some tests for the problem and try to fix it (if possible
;-)) before new release.
regards,
Armin
Jurica Viskovic wrote:
> Hy Armin
>
>
>
> Thank you for replaying so quickly.
>
>
>
> About the 'access' attribute in reference-descriptor of Bmg21. That's my
>
> stupidity because I read in some blog that it could help and I forgotten to
>
> move it later on.
>
>
>
>
>
> Object Bmt05 object exists. So there is no problem there.
>
>
>
> Going through the source code of the PersistenceBrokerImpl
>
> I found out that assertFkAssignment and storeReferences methods
>
> are setting my fields to null but I don't know why??
>
>
>
> Why this is not the case with OJB 0.9.7!
>
> Because I used OJB 0.9.7 for half of year and there were no problems!
>
>
>
>
>
> If this is the bug is there some way to fix it before the new release!
>
>
>
>
>
> Thanks,
>
> Jure
>
>
>
>
> ---------------------------------------------------------------------
> 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: Do I need to create reference objects when storing object?
Posted by Jurica Viskovic <ju...@net.hr>.
Hy Armin
Thank you for replaying so quickly.
About the 'access' attribute in reference-descriptor of Bmg21. That's my
stupidity because I read in some blog that it could help and I forgotten to
move it later on.
Object Bmt05 object exists. So there is no problem there.
Going through the source code of the PersistenceBrokerImpl
I found out that assertFkAssignment and storeReferences methods
are setting my fields to null but I don't know why??
Why this is not the case with OJB 0.9.7!
Because I used OJB 0.9.7 for half of year and there were no problems!
If this is the bug is there some way to fix it before the new release!
Thanks,
Jure
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Do I need to create reference objects when storing object?
Posted by Armin Waibel <ar...@code-au-lait.de>.
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: 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: Do I need to create reference objects when storing object?
Posted by Jurica Viskovic <ju...@net.hr>.
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: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Do I need to create reference objects when storing object?
Posted by Armin Waibel <ar...@code-au-lait.de>.
Hi Jure,
Jurica Viskovic wrote:
> Please help!
>
>
>
> In the previous versions of OJB it wasn’t necessary to create reference object
>
> when storing object that has reference but when I try the same thing with OJB
>
> 1.0 RC5 the FK fields are set by OJB to null.
>
> Is creating the reference object
>
> the right thing to do or is there some way to disable this ojb functionality?
>
Can you describe a little more? ClassDescriptor? Do you use primitive
fields as FK in referenced object? Some pseudo code?
regards,
Armin
>
>
> Thank,
>
> Jure
>
>
>
>
> ---------------------------------------------------------------------
> 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