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 Saleem Shafi <sa...@gmail.com> on 2004/07/26 21:38:58 UTC
ODMG and primary key assignment
Hello,
i have a quick question about when a primary key is assigned to an
object using the ODMG interface provided by OJB.. i realize that the
PersistentBroker.store() method will set the primary key property on
the object, but the .lock() method on the ODMG transaction doesn't
seem to do that for me.. i understand that the transactions are
different between OJB and ODMG and that the object will get its ID
after the ODMG transaction commits, but is there any way to get the ID
assigned before that?
Saleem.
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: ODMG and primary key assignment
Posted by Armin Waibel <ar...@apache.org>.
Saleem Shafi wrote:
> Hello,
>
> i have a quick question about when a primary key is assigned to an
> object using the ODMG interface provided by OJB.. i realize that the
> PersistentBroker.store() method will set the primary key property on
> the object, but the .lock() method on the ODMG transaction doesn't
> seem to do that for me.. i understand that the transactions are
> different between OJB and ODMG and that the object will get its ID
> after the ODMG transaction commits, but is there any way to get the ID
> assigned before that?
No and yes ;-)
Internally OJB use an unique Identity object (Identity.java) for each
persistent object. Identity objects based on the PK and the top-level
class of the object and the PK for new persistent objects are assigned
when the Identity object was created. So yes, it is possible to assign
the PK before an persistent object was stored (creation of an Identity
object assign the PK for new persistent objects).
But this is not possible when using native DB Identity columns for your
persistent objects (hsql, mysql, mssql,... support Identity columns). In
that case the PK was set by the DB on persistent object insert and the
PK can only extract after insert of the persistent object. OJB use in
that case a temporary PK for Identity objects created before the
persistent object was stored. Thus the answer is no, it's not guaranteed
that you get the real assigned PK before the object was stored.
regards,
Armin
>
> Saleem.
>
> ---------------------------------------------------------------------
> 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: ODMG and primary key assignment
Posted by Brian McCallister <mc...@forthillcompany.com>.
To my knowledge there isn't, though it should be possible to implement
(outside of ODMG, as I don't think ODMG provides a mechanism in its
API).
I am not sure how much rework of internal API's would be required, but
as (in most cases) OJB assigns the PK itself it could be possible to do
it early. I don't have a lot of spare cycles to dig into doing this
right now, however.
-Brian
On Jul 26, 2004, at 3:38 PM, Saleem Shafi wrote:
> Hello,
>
> i have a quick question about when a primary key is assigned to an
> object using the ODMG interface provided by OJB.. i realize that the
> PersistentBroker.store() method will set the primary key property on
> the object, but the .lock() method on the ODMG transaction doesn't
> seem to do that for me.. i understand that the transactions are
> different between OJB and ODMG and that the object will get its ID
> after the ODMG transaction commits, but is there any way to get the ID
> assigned before that?
>
>
> Saleem.
>
> ---------------------------------------------------------------------
> 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