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 "V.B. Skrypnyk" <va...@skrypnyk.net> on 2003/03/10 08:53:05 UTC

Interesting (failing) scenario of FKs/PKs in PB

Hi,

The following fails to be stored by PersistenceBroker:

I have a class ACL which has two primary keys: objectId and userFK, and
userFK is also a foreign key tied to a reference of type User. If I do this:

persistentBroker.beginTransaction();
ACL acl = new ACL();
acl.setObjectId( 100 );
acl.setUser( currentUser );
persistentBroker.store(acl);
persistentBroker.commitTransaction();

Acl will not be saved. The reason seems to be because in the storeToDb()
method of the PersistentBroker, there first comes an assertion of the
PrimaryKeys and afterwards comes the assignment of all the foreign keys. In
the scenario above the assertion of the primary keys will fail, because the
userFK has not been assigned yet, so we have an incomplete set of primary
keys. This does work with the ODMG layer, probably because of a different
sequence of events during the storing of the object.

I wonder if there should be a check whether a primary key is shared by the
foreign key and allow that assignment before the assertion of the primary
keys is performed. Any ideas?

Cheers,
--Bill.


Re: Interesting (failing) scenario of FKs/PKs in PB

Posted by "V.B. Skrypnyk" <va...@skrypnyk.net>.
Has anyone else encountered this problem?

--Bill.

> Hi,
>
> The following fails to be stored by PersistenceBroker:
>
> I have a class ACL which has two primary keys: objectId and userFK, and
> userFK is also a foreign key tied to a reference of type User. If I do
this:
>
> persistentBroker.beginTransaction();
> ACL acl = new ACL();
> acl.setObjectId( 100 );
> acl.setUser( currentUser );
> persistentBroker.store(acl);
> persistentBroker.commitTransaction();
>
> Acl will not be saved. The reason seems to be because in the storeToDb()
> method of the PersistentBroker, there first comes an assertion of the
> PrimaryKeys and afterwards comes the assignment of all the foreign keys.
In
> the scenario above the assertion of the primary keys will fail, because
the
> userFK has not been assigned yet, so we have an incomplete set of primary
> keys. This does work with the ODMG layer, probably because of a different
> sequence of events during the storing of the object.
>
> I wonder if there should be a check whether a primary key is shared by the
> foreign key and allow that assignment before the assertion of the primary
> keys is performed. Any ideas?
>
> Cheers,
> --Bill.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>