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 Tim Drury <td...@siliconmotorsports.com> on 2003/03/04 17:12:31 UTC

update setting FK to null

When I update the link object (the object between to others in an M:N
relationship), the FKs to the outer objects are being set to null in
outgoing SQL according to p6spy.  Am I forgetting to do something?  The
code is the typical,

broker.beginTransaction();
broker.store(o);
broker.commitTransaction();

everything works fine when creating the objects the first time, only
updates show this problem.

I thought there was something on the list earlier about this but, alas,
the archives (both jakarta and db) don't seem be getting updated since mid
February.

Thanks,

-tim





Re: update setting FK to null

Posted by Tim Drury <td...@siliconmotorsports.com>.
Caster - thank you.  I had set in the repository.xml not to auto-retrieve
the linked objects for Note since this would have caused a circular
reference.  While my FK IDs were correct and not null, the actual object
references were null so, as you said, it was trying to put null into the
database.  I'm not sure I understand this behavior either, but I don't
want to have my own patched ojb to maintain so I'll live with it.

I set auto-retrieve to true and the test case worked.  I think the correct
way to do this is using proxies since I don't really want to load the
linked objects because they have already been loaded.

Thanks again,

-tim


> Tim,
>
> OJB after .9.7 started to set the FK to null if the actual reference
> object is null at the time of storage. This behavior broke my programs
> and I had to comment out that line from the assertFK...() function
> inside
> PersistaeceBrokerSingleVM.
>
> I suggested making this an optional trait, to be set in the repository
> on the reference object, but haven't heard anything from the developers.
>
> Caster
> ----- Original Message -----
> From: "Tim Drury" <td...@siliconmotorsports.com>
> To: <oj...@db.apache.org>
> Sent: Tuesday, March 04, 2003 5:32 PM
> Subject: Re: update setting FK to null
>
>
>>
>> I forgot to mention I'm running 0.9.9.  Here is a little more info.
>> From my log:
>>
>> [17:08:04,955,OJBORMManager] DEBUG save: class=common.model.Note
>> [17:08:04,955,OJBORMManager] DEBUG save:
>> o=[Note:id=59,code=NOTE79,subcode=foo,ident=ID2564,desc=this is a
>> debug note,ownerId=74,docId=16]
>> [17:08:04,965,JdbcAccessImpl] ERROR SQLException during the execution
>> of the update (for a common.model.Note): ERROR:  ExecUpdate: Fail to
>> add null value in not null attribute documentid
>>
>> Note is the object that ties an Invoice and a Person object together
>> in an M:N relationship.  It's PK is id=59.  It has two foreign keys,
>> ownerId=74 points to the Person and docId=16 points to the Invoice.
>> Upon saving, it tries to put null into the DOCUMENTID database column.
>>  Here is my p6spy log:
>>
>> 1046815684955|0|0|statement|SELECT
>>
> LASTMODIFIED,DOCUMENTID,TIMECREATED,IDENTIFIER,SUBCODE,OWNERID,CODE,DESCRIPT
> ION,ID
>> FROM shipnote WHERE ID = ? |SELECT
>>
> LASTMODIFIED,DOCUMENTID,TIMECREATED,IDENTIFIER,SUBCODE,OWNERID,CODE,DESCRIPT
> ION,ID
>> FROM shipnote WHERE ID = '59'
>>
>> 1046815684965|0|0|statement|UPDATE shipnote SET TIMECREATED=?,
>> LASTMODIFIED=?, CODE=?, SUBCODE=?, IDENTIFIER=?, DESCRIPTION=?,
>> OWNERID=?, DOCUMENTID=? WHERE ID = ? |UPDATE shipnote SET
>> TIMECREATED='2003-03-04 17:08:04.154', LASTMODIFIED='2003-03-04
>> 17:08:04.154', CODE='NOTE79', SUBCODE='foo', IDENTIFIER='ID2564',
>> DESCRIPTION='this is a debug note', OWNERID='', DOCUMENTID='' WHERE ID
>> = '59'
>>
>> I also tried making a trivial change to the Invoice object and save
>> the invoice, but got the same docId=null error for the note even
>> though I had not made any changes to the note object.
>>
>> Any ideas (any!) would be appreciated,
>>
>> -tim
>>
>>
>> >
>> > When I update the link object (the object between to others in an
>> M:N relationship), the FKs to the outer objects are being set to
>> null in outgoing SQL according to p6spy.  Am I forgetting to do
>> something?  The code is the typical,
>> >
>> > broker.beginTransaction();
>> > broker.store(o);
>> > broker.commitTransaction();
>> >
>> > everything works fine when creating the objects the first time, only
>> updates show this problem.
>> >
>> > I thought there was something on the list earlier about this but,
>> alas, the archives (both jakarta and db) don't seem be getting
>> updated since mid February.
>> >
>> > Thanks,
>> >
>> > -tim
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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: update setting FK to null

Posted by casterx <ca...@netzero.net>.
Tim,

OJB after .9.7 started to set the FK to null if the actual reference object
is null at the time of storage. This behavior broke my programs and I had to
comment out that line from the assertFK...() function inside
PersistaeceBrokerSingleVM.

I suggested making this an optional trait, to be set in the repository on
the reference object, but haven't heard anything from the developers.

Caster
----- Original Message -----
From: "Tim Drury" <td...@siliconmotorsports.com>
To: <oj...@db.apache.org>
Sent: Tuesday, March 04, 2003 5:32 PM
Subject: Re: update setting FK to null


>
> I forgot to mention I'm running 0.9.9.  Here is a little more info.  From
> my log:
>
> [17:08:04,955,OJBORMManager] DEBUG save: class=common.model.Note
> [17:08:04,955,OJBORMManager] DEBUG save:
> o=[Note:id=59,code=NOTE79,subcode=foo,ident=ID2564,desc=this is a debug
> note,ownerId=74,docId=16]
> [17:08:04,965,JdbcAccessImpl] ERROR SQLException during the execution of
> the update (for a common.model.Note): ERROR:  ExecUpdate: Fail to add null
> value in not null attribute documentid
>
> Note is the object that ties an Invoice and a Person object together in an
> M:N relationship.  It's PK is id=59.  It has two foreign keys, ownerId=74
> points to the Person and docId=16 points to the Invoice.  Upon saving, it
> tries to put null into the DOCUMENTID database column.  Here is my p6spy
> log:
>
> 1046815684955|0|0|statement|SELECT
>
LASTMODIFIED,DOCUMENTID,TIMECREATED,IDENTIFIER,SUBCODE,OWNERID,CODE,DESCRIPT
ION,ID
> FROM shipnote WHERE ID = ? |SELECT
>
LASTMODIFIED,DOCUMENTID,TIMECREATED,IDENTIFIER,SUBCODE,OWNERID,CODE,DESCRIPT
ION,ID
> FROM shipnote WHERE ID = '59'
>
> 1046815684965|0|0|statement|UPDATE shipnote SET TIMECREATED=?,
> LASTMODIFIED=?, CODE=?, SUBCODE=?, IDENTIFIER=?, DESCRIPTION=?, OWNERID=?,
> DOCUMENTID=? WHERE ID = ? |UPDATE shipnote SET TIMECREATED='2003-03-04
> 17:08:04.154', LASTMODIFIED='2003-03-04 17:08:04.154', CODE='NOTE79',
> SUBCODE='foo', IDENTIFIER='ID2564', DESCRIPTION='this is a debug note',
> OWNERID='', DOCUMENTID='' WHERE ID = '59'
>
> I also tried making a trivial change to the Invoice object and save the
> invoice, but got the same docId=null error for the note even though I had
> not made any changes to the note object.
>
> Any ideas (any!) would be appreciated,
>
> -tim
>
>
> >
> > When I update the link object (the object between to others in an M:N
> > relationship), the FKs to the outer objects are being set to null in
> > outgoing SQL according to p6spy.  Am I forgetting to do something?  The
> > code is the typical,
> >
> > broker.beginTransaction();
> > broker.store(o);
> > broker.commitTransaction();
> >
> > everything works fine when creating the objects the first time, only
> > updates show this problem.
> >
> > I thought there was something on the list earlier about this but, alas,
> > the archives (both jakarta and db) don't seem be getting updated since
> > mid February.
> >
> > Thanks,
> >
> > -tim
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>


Re: update setting FK to null

Posted by Tim Drury <td...@siliconmotorsports.com>.
I forgot to mention I'm running 0.9.9.  Here is a little more info.  From
my log:

[17:08:04,955,OJBORMManager] DEBUG save: class=common.model.Note
[17:08:04,955,OJBORMManager] DEBUG save:
o=[Note:id=59,code=NOTE79,subcode=foo,ident=ID2564,desc=this is a debug
note,ownerId=74,docId=16]
[17:08:04,965,JdbcAccessImpl] ERROR SQLException during the execution of
the update (for a common.model.Note): ERROR:  ExecUpdate: Fail to add null
value in not null attribute documentid

Note is the object that ties an Invoice and a Person object together in an
M:N relationship.  It's PK is id=59.  It has two foreign keys, ownerId=74
points to the Person and docId=16 points to the Invoice.  Upon saving, it
tries to put null into the DOCUMENTID database column.  Here is my p6spy
log:

1046815684955|0|0|statement|SELECT
LASTMODIFIED,DOCUMENTID,TIMECREATED,IDENTIFIER,SUBCODE,OWNERID,CODE,DESCRIPTION,ID
FROM shipnote WHERE ID = ? |SELECT
LASTMODIFIED,DOCUMENTID,TIMECREATED,IDENTIFIER,SUBCODE,OWNERID,CODE,DESCRIPTION,ID
FROM shipnote WHERE ID = '59'

1046815684965|0|0|statement|UPDATE shipnote SET TIMECREATED=?,
LASTMODIFIED=?, CODE=?, SUBCODE=?, IDENTIFIER=?, DESCRIPTION=?, OWNERID=?,
DOCUMENTID=? WHERE ID = ? |UPDATE shipnote SET TIMECREATED='2003-03-04
17:08:04.154', LASTMODIFIED='2003-03-04 17:08:04.154', CODE='NOTE79',
SUBCODE='foo', IDENTIFIER='ID2564', DESCRIPTION='this is a debug note',
OWNERID='', DOCUMENTID='' WHERE ID = '59'

I also tried making a trivial change to the Invoice object and save the
invoice, but got the same docId=null error for the note even though I had
not made any changes to the note object.

Any ideas (any!) would be appreciated,

-tim


>
> When I update the link object (the object between to others in an M:N
> relationship), the FKs to the outer objects are being set to null in
> outgoing SQL according to p6spy.  Am I forgetting to do something?  The
> code is the typical,
>
> broker.beginTransaction();
> broker.store(o);
> broker.commitTransaction();
>
> everything works fine when creating the objects the first time, only
> updates show this problem.
>
> I thought there was something on the list earlier about this but, alas,
> the archives (both jakarta and db) don't seem be getting updated since
> mid February.
>
> Thanks,
>
> -tim